我正在使用具有文本视图和编辑文本的列表视图。我正在通过ViewHolder
. 问题是,当我在第一列和第二列中写入数据时,屏幕上可见的部分以及滚动时,第一行的数据会自动复制到最后一行。
这是代码:
private class MobileArrayAdapter extends ArrayAdapter
{
ViewHolder holder;
private Context context;
private ArrayList values;
@SuppressWarnings("unchecked")
public MobileArrayAdapter(Context context, ArrayList values)
{
super(context, R.layout.taskstrt, values);
this.context = context;
this.values = values;
System.out.println("in mobile constructor");
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.taskstrt, parent, false);
holder.editText = (EditText) convertView.findViewById(R.id.editText1);
holder.textView = (TextView) convertView.findViewById(R.id.textView1);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(values.get(position).toString());
holder.textView.setId(position);
holder.editText.setId(position);
holder.editText.setFocusable(false);
// holder.editText.setFocusableInTouchMode(true);
holder.editText.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
final int positio = v.getId();
edittexthold = (EditText) v;
textholder = (TextView) v;
edittexthold.setFocusable(true);
if (edittexthold.getText().toString().length() > 0)
{
HashMap<Integer, String> Map = new HashMap<Integer, String>();
Map.put(positio, edittexthold.getText().toString());
data.set(positio, Map);
System.out.println(data);
}
System.out.println(positio + " this is position that is clicked");
if (positio == 4)
{
System.out.println("going to assign ID");
qq = positio;
showDialog(NAME_LIST);
}
if (positio == 5)
{
qq = positio;
System.out.println("going to start time ID");
showDialog(STARTTIME);
}
if (positio == 3)
{
qq = positio;
System.out.println("going to date picker ID");
showDialog(DATE_DIALOG_ID);
}
}
}) ;
holder.editText.setOnFocusChangeListener(new OnFocusChangeListener()
{
public void onFocusChange(View v, boolean hasFocus)
{
//if(!hasFocus)
{
final int positio = v.getId();
String conv = null;
final EditText edittexthold = (EditText) v;
final TextView textholder = (TextView) v;
edittexthold.setFocusable(true);
if (edittexthold.getText().toString().length() > 0)
{
HashMap<Integer, String> Map = new HashMap<Integer, String>();
Map.put(positio, edittexthold.getText().toString());
data.set(positio, Map);
System.out.println(data);
}
edittexthold.setFocusable(false);
}
}
});