我有listview,它将textview和editText保存为行条目。构建列表后,用户可以单击特定的editText并提供值并滚动到另一个并执行相同操作。这是根据需要实现的,不会在editText条目中重复数据。然而,当我点击一个edittext时,我发现其他人也已经集中在下面。我有下面的自定义适配器的代码:我还为主机活动添加了android:windowSoftInputMode =“adjustPan”
public class StockWatch_Adapter extends BaseAdapter {
private Activity activity;
private static LayoutInflater inflater = null;
public ArrayList<HashMap<String, String>> filteredData;
private String [] arrTemp;
public StockWatch_Adapter (Activity a, ArrayList<HashMap<String, String>> d)
{
activity = a;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
filteredData = d;
arrTemp = new String [filteredData !=null ? filteredData.size() : 0];
}
public int getCount()
{
return filteredData !=null ? filteredData.size() : 0;
}
public Object getItem(int position)
{
return filteredData.get(position);
}
public long getItemId(int position)
{
return position;
}
public static class ViewHolder {
TextView sku;
EditText sku_quantity;
int ref;
}
public View getView(int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
View vi = convertView;
if(convertView==null){
vi = inflater.inflate(R.layout.layout_cocacola__listrow, parent, false);
holder = new ViewHolder();
holder.sku = (TextView)vi.findViewById(R.id.lbl_sku);
holder.sku_quantity = (EditText)vi.findViewById(R.id.edtxt_quantity);
vi.setTag(holder);
}
else {
holder = (ViewHolder) vi.getTag();
}
HashMap<String, String> accounts = new HashMap<String, String>();
accounts = filteredData.get(position);
holder.ref=position;
holder.sku.setText( accounts.get(StockWatch_OpeningStock.KEY_SKU));
holder.sku_quantity.setText(arrTemp[position]);
holder.sku_quantity.addTextChangedListener(new TextWatcher(){
@Override
public void onTextChanged(CharSequence args,int arg1,int ar2,int arg3){
}
@Override
public void beforeTextChanged (CharSequence args,int arg1,int ar2,int arg3){
}
@Override
public void afterTextChanged (Editable arg0){
arrTemp[holder.ref]=arg0.toString();
}
});
return vi;
}
}