android - putExtra inside onClickListener within ListView -


i android newbie, , have problem regarding listview. have many elements inside 1 row of listview, , want them clickable individually , show different activities.

this listview-

<listview     android:id="@+id/maincontentlist"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:cachecolorhint="#00000000"     android:dividerheight="15dp"     android:divider="#00000000"     android:scrollbarstyle="outsideinset"     android:paddingright="10dp"     android:paddingleft="10dp" /> 

this single row of listview-

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shadow"      > <linearlayout     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="@color/lightgrey"     android:layout_gravity="center_horizontal"     android:orientation="vertical" > <!-- add padding=10dp every layout text.  --> <linearlayout     android:id="@+id/singlepagelink"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="vertical"     android:clickable="true"             >     <relativelayout          android:layout_height="wrap_content"         android:layout_width="match_parent"         style="@style/maincontentlist"         >         <imageview             android:id="@+id/profilepic"             android:layout_height="fill_parent"             android:layout_width="wrap_content"             android:src="@drawable/ic_launcher"             android:layout_alignparentleft="true"             android:layout_alignparenttop="true"             android:layout_alignparentbottom="true"             android:padding="2dp"             android:contentdescription="@string/imgdesc"         />         <textview             android:id="@+id/author"             android:layout_width="fill_parent"             android:layout_height="26dp"             android:layout_torightof="@id/profilepic"             android:layout_alignparenttop="true"             android:layout_alignparentright="true"             android:gravity="center_vertical"         />         <textview             android:id="@+id/status"             android:layout_width="fill_parent"             android:layout_height="26dp"             android:layout_torightof="@id/profilepic"             android:layout_alignparentbottom="true"             android:layout_alignparentright="true"             android:layout_below="@id/author"             android:gravity="center_vertical"             android:textsize="14sp"         />      </relativelayout>     <view         android:layout_width="fill_parent"         android:layout_height="@dimen/linethickness"         style="@style/horizontalline"     />     <linearlayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         style="@style/maincontentlist"     >         <textview             android:id="@+id/title"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:gravity="center_horizontal|center_vertical"             />          <textview             android:id="@+id/time"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:textsize="15sp"             android:gravity="right"         />         <textview             android:id="@+id/message"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:textsize="15sp"             android:visibility="gone"          />     </linearlayout> </linearlayout>     <view         android:layout_width="fill_parent"         android:layout_height="@dimen/linethickness"         style="@style/horizontalline"     />     <linearlayout     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="@color/lightgrey"     android:layout_gravity="center_horizontal"     android:orientation="vertical"     android:clickable="true"     >         <imageview             android:id="@+id/noteslink"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:contentdescription="@null"             android:src="@drawable/ic_launcher"             android:clickable="true"                     />     </linearlayout> </linearlayout> 

and i've used baseadapter populate listview.

public class updatecontentadapter extends baseadapter{ //i've implemented updatecontentadapter() constructor, getcount, getitem, getitemid. //this getview() public view getview(int index, view view, viewgroup parent){     linearlayout spl=(linearlayout)view.findviewbyid(r.id.singlepagelink);     spl.setonclicklistener(new onclicklistener(){         public void onclick(view view){             try{                 intent intent=new intent(view.getcontext(),class.forname("com.example.justtopics."+(string)view.findviewbyid(r.id.title).gettag()));                 //this line creates problem.                 intent.putextra("tag","content");                 //if line removed, able go next activity.                 view.getcontext().startactivity(intent);             }catch(exception e){                 log.d("error","id:singlepagelink not found.");             }         }     });     return view; } } 

when use intent.putextra("tag","content"), app crashes, , when don't, able go next activity. in next activity have performed checks see if content null or not, not problem. error handling i've performed in next activity-

bundle obj = getintent().getextras(); if (obj != null) {     toast.maketext(getapplicationcontext(), "success!", toast.length_short).show(); } else{     toast.maketext(getapplicationcontext(), "no data!", toast.length_short).show(); } 

my main problem not able understand why app crashes when use putextras() inside updatecontentadapter class. i've put class separately in file, public.

hopefully, clear enough problem.any other simplified methods performing task welcome.


Comments