Я использую GridView для отображения категорий, я использовал ImageButton и Text View в Grid View, но я не могу setOnItemClickListener на этих элементах (Imean nothings Happening при нажатии на него) Мой код это My Adapter for GridView
public class MyAdapter extends BaseAdapter{
private ArrayList<String> listJewel_name;
private ArrayList<Integer> listJewellery;
private Activity activity;
//private LayoutInflater inflater;
public MyAdapter(Activity activity,ArrayList<String> listJewel_name, ArrayList<Integer> listJewellery) {
super();
this.listJewel_name = listJewel_name;
this.listJewellery = listJewellery;
this.activity = activity;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return listJewel_name.size();
}
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return listJewel_name.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public static class ViewHolder
{
public ImageButton imgViewJewel;
public TextView txtViewTitle;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder view;
LayoutInflater inflator = activity.getLayoutInflater();
if(convertView==null)
{
view = new ViewHolder();
convertView = inflator.inflate(R.layout.gridview, null);
view.txtViewTitle = (TextView) convertView.findViewById(R.id.tvtext);
view.imgViewJewel = (ImageButton) convertView.findViewById(R.id.picture);
convertView.setTag(view);
}
else
{
view = (ViewHolder) convertView.getTag();
}
view.txtViewTitle.setText(listJewel_name.get(position));
view.imgViewJewel.setImageResource(listJewellery.get(position));
return convertView;
}
}
My activity.class
GridView gridView;
Button add;
private MyAdapter mAdapter;
private ArrayList<String> listJewel_name;
private ArrayList<Integer> listJewellery;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_jewellery_option);
prepareList();
// prepared arraylist and passed it to the Adapter class
mAdapter = new MyAdapter(this,listJewel_name, listJewellery);
// Set custom adapter to gridview
gridView = (GridView) findViewById(R.id.gridview);
gridView.setAdapter(mAdapter);
// Implement On Item click listener
gridView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
String shri=mAdapter.getItem(position);
Toast.makeText(SelectJewelleryOption.this, shri , Toast.LENGTH_SHORT).show();
}
});
}
Мой XML файл
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.myjewelbox.SquareImageButtonView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="130dp"
android:scaleType="fitCenter"
android:clickable="true" />
<TextView
android:id="@+id/tvtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="1dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_gravity="bottom"
android:textColor="@color/Golden"
android:background="#55000000"
android:focusable="false"
/>
</FrameLayout>
И я установил этот файл XMl в свой основной файл XML GridView