android - Intent is not working in fragment -


i have below code :

public class homefragment extends fragment {     private list<rowitem> rowitems;      private static integer[] images = { r.drawable.red, r.drawable.spidy,             r.drawable.prisoners, r.drawable.red, r.drawable.spidy };      public homefragment() {     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {          view rootview = inflater.inflate(r.layout.fragment_home, container,                 false);         listview lv = (listview) rootview.findviewbyid(r.id.mylist);         rowitems = new arraylist<rowitem>();          string[] titles = { "movie1", "movie2", "movie3", "movie4", "movie5" };         string[] descriptions = { "first movie", "second movie", "third movie",                 "fourth movie", "fifth movie" };         // populate list         (int = 0; < titles.length; i++) {             rowitem item = new rowitem(images[i], titles[i], descriptions[i]);             rowitems.add(item);         }          // set adapter on listview         lazyadapter adapter = new lazyadapter(getactivity()                 .getapplicationcontext(), r.layout.list_row, rowitems);         lv.setadapter(adapter);          lv.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id) {                  toast.maketext(getactivity(), "test", toast.length_long).show();                 intent myintent = new intent(getactivity(), news.class);                 getactivity().startactivity(myintent);                  // startactivity(in);             }         });         lv.setonitemselectedlistener(new onitemselectedlistener() {              @override             public void onitemselected(adapterview<?> arg0, view arg1,                     int arg2, long arg3) {                 // todo auto-generated method stub              }              @override             public void onnothingselected(adapterview<?> arg0) {                 // todo auto-generated method stub              }         });         return rootview;     }     } 

i have written toast ans startintent on item click, not working. neither toast display nor new activity starting. have tried onitemselection method not working. how can used in fragment class?

list_row.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/card"     android:layout_width="fill_parent"     android:layout_height="match_parent"     android:background="@drawable/card_greenborder"     android:focusable="false"     android:focusableintouchmode="false"     android:orientation="vertical"     android:padding="2dp" >      <textview         android:id="@+id/title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:text="dog tag"         android:textappearance="?android:attr/textappearancelarge"         android:textcolor="#040404"         android:textstyle="bold"         android:typeface="sans" />      <imageview         android:id="@+id/list_image"         android:layout_width="match_parent"         android:layout_height="180dp"         android:layout_margin="2dp"         android:layout_weight="0.04"         android:scaletype="fitxy"         android:src="@drawable/dhoom" />      <textview         android:id="@+id/description"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:text="create nfc pet tag"         android:textappearance="?android:attr/textappearancemedium"         android:textcolor="@android:color/secondary_text_dark"         android:textstyle="bold" />      <button         android:id="@+id/btnregister"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="register" />  </linearlayout> 

first don't need implement onitemselectedlistener listview. remove it.

second make

android:focusable = "false" android:focusableintouchmode = "false" 

for uis in custom inflated views in listview


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -