您好,我對這個問題很感興趣。我有一些動態創建的spinners。請幫助我從這些spinners獲取數據。從多個紡紗廠獲取數據?
當點擊添加按鈕應該從所有的紡紗廠獲得數據。對於按鈕
碼點擊
btnSave.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String[] strings = new String[allEds.size()];
String[] stringSpinns = new String[allSpns.size()];
for(int i=0; i < allEds.size(); i++){
strings[i] = allEds.get(i).getText().toString();
try
{
json.put("Name", strings[i]);
//json.put("Description", descOfFolder);
Log.w("ANDROID DYNAMIC VIEWS:", "View Id: " + json);
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
微調與此代碼
public void addSpinner() {
LinearLayout rAlign = (LinearLayout)findViewById(R.id.lId);
List<String> list = new ArrayList<String>();
list.add("Net Banking Id");
list.add("Net Banking password");
list.add("Account Number");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
Log.w("ANDROID DYNAMIC VIEWS:", "View Id: " + dataAdapter);
LinearLayout spinnerHolder = new LinearLayout(getApplicationContext());
spinnerHolder.setOrientation(LinearLayout.HORIZONTAL);
spinnerHolder.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
Spinner newSpinner = new Spinner(getApplicationContext());
allSpns.add(newSpinner);
newSpinner.setLayoutParams(
new Spinner.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
newSpinner.setAdapter(dataAdapter);
rAlign.addView(spinnerHolder);
spinnerHolder.addView(newSpinner);
Log.w("ANDROID DYNAMIC VIEWS:", "View Id: " + allSpns);
}
創建的列表動態添加跟蹤紡紗的數量和開放獲取數據的循環。
String[] stringSpinns = new String[allSpns.size()];
但感到困惑如何將數據...
發表您正在面臨問題的代碼? –
@ Ram kiran yes更新了代碼 – user1682133