android - How to start different activities on click of different recycler views -


i have recyclerview gridlayoutmanager. on click of each item want tstart different acticities. have tried not working. dashboardadapter class

 public class dashboardadapter extends recyclerview.adapter<dashboardadapter.viewholder>{  private list<dashboardpojo> countries; private int rowlayout; private context mcontext;  public dashboardadapter(list<dashboardpojo> countries, int rowlayout, context context) {     this.countries = countries;     this.rowlayout = rowlayout;     this.mcontext = context; }  @override public viewholder oncreateviewholder(viewgroup viewgroup, int i) {     view v = layoutinflater.from(viewgroup.getcontext()).inflate(rowlayout, viewgroup, false);     return new viewholder(v); }  @override public void onbindviewholder(viewholder viewholder, int i) {     dashboardpojo country = countries.get(i);     viewholder.countryname.settext(country.name);     viewholder.countryimage.setimageresource(country.getimageresourceid(mcontext)); }  @override public int getitemcount() {     return countries == null ? 0 : countries.size(); }  public class viewholder extends recyclerview.viewholder implements view.onclicklistener{     public textview countryname;     public imageview countryimage;      public viewholder(view itemview) {         super(itemview);         mcontext = itemview.getcontext();         itemview.setonclicklistener(this);         countryname = (textview) itemview.findviewbyid(r.id.countryname);         countryimage = (imageview)itemview.findviewbyid(r.id.countryimage);     }     @override     public void onclick(view v) {          final intent intent;         if (getposition() == 0){             intent =  new intent(mcontext, tutorialactivity.class);         } else if (getposition() == 1){             intent =  new intent(mcontext, jobsactivity.class);         } else {             intent =  new intent(mcontext, tutorialactivity.class);         }         mcontext.startactivity(intent);     } }  } 

and in dashboardactivity have

    mrecyclerview = (recyclerview) findviewbyid(r.id.list);     mlayoutmanager = new gridlayoutmanager(this, 2);     mrecyclerview.setlayoutmanager(mlayoutmanager);     mrecyclerview.setitemanimator(new defaultitemanimator());     madapter = new dashboardadapter(dashboardmanager.getinstance().getcountries(), r.layout.dashboard_row, this);     mrecyclerview.setadapter(madapter); 

and dashboard_row.xml

     <?xml version="1.0" encoding="utf-8"?>  <android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_margin="5dp" card_view:cardcornerradius="5dp" android:layout_height="match_parent">  <relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent">      <imageview         android:id="@+id/countryimage"         android:layout_width="match_parent"         android:layout_height="120dp"         android:scaletype="centercrop"         android:tint="@color/photo_tint"         android:layout_centerinparent="true"         />      <textview         android:id="@+id/countryname"         android:gravity="center"         android:background="?android:selectableitembackground"         android:focusable="true"         android:clickable="true"         android:layout_width="match_parent"         android:layout_height="100dp"         android:textsize="24sp"         android:layout_centerinparent="true"         android:textcolor="@android:color/white"         />  </relativelayout>   </android.support.v7.widget.cardview> 

activity_dashboard.xml

         <android.support.v4.widget.drawerlayout       xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent">  <relativelayout     android:id="@+id/rel"     android:layout_width="wrap_content"     android:layout_height="fill_parent">      <include         android:id="@+id/app_bar"         layout="@layout/app_bar" />      <android.support.v7.widget.recyclerview     android:id="@+id/list"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".dashboardactivity"     android:layout_below="@+id/app_bar"     android:layout_margintop="20dp"/>   </relativelayout>  <fragment     android:id="@+id/fragment_navigation_drawer"     android:name="solutions.techieweb.com.techiewebsolutions.navigationdrawerfragment"     android:layout_width="280dp"     android:layout_height="match_parent"     android:layout_gravity="start"     app:layout="@layout/fragment_navigation_drawer"     tools:layout="@layout/fragment_navigation_drawer" />     </android.support.v4.widget.drawerlayout> 

please me....

from u have posted seems view onclick() event consumed textview

please remove :

 android:focusable="true"  android:clickable="true" 

tag countryname textview

and change getposition() getadapterposition() getposition() deprecated


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -