我正在尝试使用自定义适配器向我的第一个Android应用添加可点击列表 一切都很好但是当我使用
时mItemList.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_LONG).show();
Log.d("error", "error here");
}
});
但没有回应 没有吐司 尽管列表显示良好
,但没有错误自定义适配器
public class ItemListAdapter extends BaseAdapter {
public Context context;
public ArrayList<ItemModel> items;
.....
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View grid;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null ) {
grid = new View(context);
grid = mInflater.inflate(R.layout.item, null);
Button bt = (Button) grid.findViewById(R.id.btn_list);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/font1.otf");
bt.setText(items.get(position).getTitle().toString());
bt.setTypeface(tf);
}else{
grid = (View) convertView;
}
return grid;
}
....
}
答案 0 :(得分:3)
如果您的商品布局中有Button
,ImageButton
,CheckBox
或RadioButton
,请将这些属性添加到其中:
android:focusable="false"
android:focusableInTouchMode="false"