I'm trying to add a clickable list to my first android app with Custom Adapter all is fine but when i use
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");
}
});
but there is no response no toast no errors despite the list showing good
Custom Adapter
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;
}
....
}
If you have Button
, ImageButton
, CheckBox
or RadioButton
inside your item layout, add these properties to them:
android:focusable="false"
android:focusableInTouchMode="false"