Question

Here's My Code the code, I'm not getting any response from gridview setOnClickListener. Please Help me out.

setContentView(R.layout.myfav);
gView = (GridView) findViewById(R.id.grid);
PackageManager pm = this.getPackageManager();
    context = MyFav.this;
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    list = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
    gView.setAdapter(new MyAdapter());
    // save.setOnClickListener(this);
    // cancel.setOnClickListener(this);
    gView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            Log.e("inside click", "" + arg2);
            Toast.makeText(getApplicationContext(), "Hello" + arg2,
                    Toast.LENGTH_SHORT).show();
        }
    });

This is my Grid view

<GridView
    android:id="@+id/grid"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:layout_centerHorizontal="true"
    android:numColumns="3"
    android:stretchMode="columnWidth" >
</GridView>
Was it helpful?

Solution

It could be that some items in your GridView are stealing focus. Try adding these attributes to any elements you have inside the grid:

android:focusable="false"
android:focusableInTouchMode="false"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top