我在我的 Listview 上设置了 2 到 3 个监听器,但没有一个监听器在工作(但一次只应用了任何 1 个监听器。)我正在使用自定义适配器。我每次都成功地在 listview 中获取数据意味着对象不是空白的。但是在点击行时,我无法执行任何操作。我正在使用下面的代码。我也尝试过 onItemSelectedListner 但这也不起作用。
MyAdapter myadptr = new MyAdapter();
lv.setAdapter(myadptr);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(ContactBookActivity.this,
" inside setOnItemClickListener ", 300).show();
}
});
在 logcat 我得到了这个
任何人都可以告诉我为什么会发生这种情况,因为我不是第一次使用此代码。在我的其他项目中,相同的代码适用于我。请帮助!
编辑
class MyAdapter extends BaseAdapter {
private ViewHolder holder;
@Override
public int getCount() {
// TODO Auto-generated method stub
return inflatList.size() - 1;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return inflatList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater lf = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
convertView = lf.inflate(R.layout.importlist_inflator, null);
holder = new ViewHolder();
holder.in_ll = (LinearLayout) convertView.findViewById(R.id.in_ll);
holder.im = (ImageView) convertView.findViewById(R.id.infltimg);
holder.txtname = (TextView) convertView.findViewById(R.id.txtname);
holder.phn_import = (TextView) convertView
.findViewById(R.id.phn_import);
holder.eid_import = (TextView) convertView
.findViewById(R.id.eid_import);
convertView.setEnabled(true);
// inflatList = dbh.reteriveContactInfo();
int indx = 0;
String did = inflatList.get(position).get(indx).toString();
String name = inflatList.get(position).get(++indx).toString();
// txtname.setText(inflatList.get(position).get(indx).toString());
holder.phn_import.setText(inflatList.get(position).get(++indx)
.toString());
holder.eid_import.setText(inflatList.get(position).get(++indx)
.toString());
ByteArrayInputStream inputStream = new ByteArrayInputStream(
(byte[]) inflatList.get(position).get(++indx));
Bitmap mBitmap = BitmapFactory.decodeStream(inputStream);
holder.im.setImageBitmap(mBitmap);
holder.txtname.setText(name);
return convertView;
}