我有一个自定义 listView,它为每一行加载一个 TextView、一个 ImageView 和一个复选框。
管理我使用的单个项目
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
long x = MyClass.this.adapter.getItemId(position);
......
}
});
这允许我获取单个单击行的 id x,我可以使用它来检索与单行关联的数据。
现在:
如何获得所有点击行的各种位置索引?
我的 ListAdapter 是
public class MyAdapter extends BaseAdapter{
private Activity activity;
private String[] dataCar;
private String[] dataImm;
private static LayoutInflater inflater=null;
public TitleLoader titleLoader;
public ImageLoader imageLoader;
public TextLoader textLoader;
public MyAdapter(Activity a, String[] dCar, String[] dImm) {
activity = a;
dataCar=dCar;
dataImm=dImm;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
titleLoader=new TitleLoader(activity.getApplicationContext());
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return dataImm.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.elemento_lista_car, null);
TextView car=(TextView)vi.findViewById(R.id.car);
ImageView image=(ImageView)vi.findViewById(R.id.image);
CheckBox cb=(CheckBox)vi.findViewById(R.id.checkBox);
titleLoader.DisplayTitle(dataCar[position], car);
imageLoader.DisplayImage(dataImm[position], image);
return vi;
}
}