我正在尝试为我的第一个带有自定义适配器的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;
}
....
}
如果您的项目布局中有Button
、ImageButton
、CheckBox
或RadioButton
,请向它们添加以下属性:
android:focusable="false"
android:focusableInTouchMode="false"