嗨,这个问题让我很震惊。我有许多动态创建的微调器。请帮助我从这些微调器中获取数据。
单击添加按钮时,应从所有微调器获取数据。
按钮点击代码
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()];
但是对如何获取数据感到困惑......