Note that there are some explanatory texts on larger screens.

plurals
  1. PONothings happening on clicking items of GridView
    primarykey
    data
    text
    <p>I am using GridView for displaying the categories , i have used ImageButton and a Text View in Grid View but I am not able to setOnItemClickListener on those items( Imean nothings Happening on Clicking it) My code is this is My Adapter for GridView</p> <pre><code>public class MyAdapter extends BaseAdapter{ private ArrayList&lt;String&gt; listJewel_name; private ArrayList&lt;Integer&gt; listJewellery; private Activity activity; //private LayoutInflater inflater; public MyAdapter(Activity activity,ArrayList&lt;String&gt; listJewel_name, ArrayList&lt;Integer&gt; 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; } } </code></pre> <p>My activity.class is</p> <pre><code>GridView gridView; Button add; private MyAdapter mAdapter; private ArrayList&lt;String&gt; listJewel_name; private ArrayList&lt;Integer&gt; 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&lt;?&gt; parent, View v, int position, long id) { String shri=mAdapter.getItem(position); Toast.makeText(SelectJewelleryOption.this, shri , Toast.LENGTH_SHORT).show(); } }); } </code></pre> <p>My XML file is </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;com.myjewelbox.SquareImageButtonView android:id="@+id/picture" android:layout_width="match_parent" android:layout_height="130dp" android:scaleType="fitCenter" android:clickable="true" /&gt; &lt;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" /&gt; &lt;/FrameLayout&gt; </code></pre> <p>And I have set this XMl file to my Main XML file's GridView</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload