ListView 内に存在するすべての EditText 要素のすべての値を取得したいと考えています。これは私のコードです:
final ListView editorList = (ListView) findViewById(R.id.editorList);
final EditorAdapter adapter = new EditorAdapter(context, data);
editorList.setAdapter(adapter);
Button commitButton = (Button) findViewById(R.id.commit_button);
commitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
//System.out.println("Size of List : " + editorList.getChildCount());
for(int i =0;i< data.size() ;i++){
System.out.println("Size of List : " + data.size());
EditText value = adapter.getItem(i);
String propertyValue = value.getText().toString();
System.out.println("PropertyValue : " + propertyValue);
}
} catch (Exception e){
e.printStackTrace();
}
}
});
これは私のアダプタクラスです:
package in.omerjerk.preferenceseditor;
public class EditorAdapter extends BaseAdapter {
Context context;
ArrayList<HashMap<String,String>> data;
EditText[] mHolders;
public EditorAdapter(Context context, ArrayList<HashMap<String,String>> data){
this.context = context;
this.data = data;
System.out.println("No . of items in nodes"+data.size());
mHolders = new EditText[data.size()];
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public EditText getItem(int pos) {
// TODO Auto-generated method stub
return mHolders[pos];
}
@Override
public long getItemId(int pos) {
// TODO Auto-generated method stub
return pos;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView==null){
System.out.println("CONVERT VIEW IS NULL");
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.row_edit_string,null,false);
holder.editPropertyValue = (EditText) convertView.findViewById(R.id.propertyValue);
holder.propertyName = (TextView) convertView.findViewById(R.id.propertyName);
holder.propertyName.setText(data.get(position).get("propertyName"));
holder.editPropertyValue.setText(data.get(position).get("propertyName"));
convertView.setTag(holder);
}else{
System.out.println("CONVERT VIEW NOT NULL");
holder = (ViewHolder) convertView.getTag();
holder.propertyName.setText(data.get(position).get("propertyName"));
holder.editPropertyValue.setText(data.get(position).get("propertyName"));
convertView.setTag(holder);
mHolders[position] = new EditText(context);
mHolders[position] = holder.editPropertyValue;
}
return convertView;
}
}
出力に奇妙なエラーが表示されます。mHolders 配列には最大 6 ~ 7 個の要素のみが含まれ、これらの要素は配列全体で繰り返されます。EditText の値を取得できますが、エラーは正しくありません。