Android GridView not responding to OnItemClickListener -


i found people had problem well, none of existing solutions worked me. have fragment (called headlinesfragment), assigns onitemclicklistener gridview containing images. images appear fine, touch/click event never fired. tried multiple combinations of android:clickable="false"/android:focusable="false", etc nothings works me

public static class headlinesfragment extends fragment {      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {          view rootview = inflater.inflate(r.layout.menufragment, container, false);         return rootview;     }      public class imageadapter extends baseadapter {         private context context;          integer[] imageids = {                 r.drawable.pasta05,                 r.drawable.pasta05,                 r.drawable.pasta05,                 r.drawable.pasta05,                 r.drawable.pasta05,                 r.drawable.pasta05,                 r.drawable.pasta05         };          public imageadapter(context c) {             context = c;         }          //---returns number of images---         public int getcount() {             return imageids.length;         }          //---returns id of item---         public object getitem(int position) {             return position;         }          public long getitemid(int position) {             return position;         }          //---returns imageview view---         public view getview(int position, view convertview, viewgroup parent) {             imageview imageview;             if (convertview == null) {                 imageview = new imageview(context);                 imageview.setlayoutparams(new gridview.layoutparams(185, 185));                 imageview.setscaletype(imageview.scaletype.center_crop);                 imageview.setpadding(5, 5, 5, 5);             } else {                 imageview = (imageview) convertview;             }             imageview.setimageresource(imageids[position]);             return imageview;         }     }     gridview gridview;     @override     public  void onactivitycreated (bundle savedinstancestate){         super.oncreate(savedinstancestate);          gridview = (gridview) getview().findviewbyid(r.id.gridview);          gridview.setonitemclicklistener(new onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                 toast.maketext(getactivity().getapplicationcontext(), "sssssx", toast.length_short).show();                 system.out.println("r=");              }          });         gridview.setadapter(new imageadapter(getactivity()));     } } 

on other hand, xml fragment containing gridview:

<?xml version="1.0" encoding="utf-8"?> 

    <gridview         android:id="@+id/gridview"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:gravity="center"         android:focusableintouchmode="false"         android:clickable="false"         android:focusable="false"         android:numcolumns="3"         android:descendantfocusability="blocksdescendants"         android:stretchmode="columnwidth" >     </gridview> 

and finally, xml containing main activity hosts fragment.

<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:components="http://schemas.android.com/apk/res-auto" android:background="#0099cc" tools:context="com.purplemechanics.rest_a_urant.fullscreenactivity">  <!-- primary full-screen view. can replaced whatever view      needed present content, e.g. videoview, surfaceview,      textureview, etc. -->   <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="match_parent" android:descendantfocusability="blocksdescendants"  android:id="@+id/richardo">       </linearlayout>  <!-- framelayout insets children based on system windows using      android:fitssystemwindows. -->       <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/drawer_layout"         android:layout_width="match_parent"         android:layout_height="match_parent" >          <relativelayout             xmlns:tools="http://schemas.android.com/tools"             android:layout_width="match_parent"             android:layout_height="match_parent"             tools:context=".mainactivity" >               <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:textappearance="?android:attr/textappearancelarge"                 android:text="large text"                 android:id="@+id/textview2"                 android:layout_alignparenttop="true"                 android:layout_centerhorizontal="true"                 android:layout_margintop="112dp" />         </relativelayout>          <listview             android:id="@+id/list_view"             android:layout_width="300dp"             android:layout_height="match_parent"             android:layout_gravity="start"             android:background="#007095"             android:choicemode="singlechoice"             android:divider="#005875"             android:dividerheight="2dp"             android:textcolor="#ffffff"             />     </android.support.v4.widget.drawerlayout> 

try instantiating new adapterview.onitemclicklistener() following:

gridview.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             toast.maketext(getactivity().getapplicationcontext(), "sssssx", toast.length_short).show();             system.out.println("r=");          }      }); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -