java - Change view on button click from CustomAdapter -
i have created layout contains listview, view populated multiple similar elements in oncreateview function fragment, view populated in customadapter extends baseadapter. in each element of listview have button want implement onclicklistener. when button clicked want switch view, similar viewing comments on googleplus mobile app. have tried doing way in customadapter:
public void setonclickcomment(view view) { final imagebutton btn = (imagebutton)view.findviewbyid(r.id.addcomment); if (btn != null) { btn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.d("onclick", "i clicked shit" + btn.gettag()); manager.begintransaction() .replace(r.id.feedlayout, new commentfragment()).commit(); } }); } else { log.d("click", "este null"); } }
the manager fragmentmanager , it's passed fragment customadapter constructor. can see log in logcat that's nothing else happens, tag of button position of element.
this layout:
<?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="fill_parent" android:orientation="vertical" android:id="@+id/feedlayout" > <listview android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:divider="#b5b5b5" android:dividerheight="1dp" android:listselector="@drawable/list_selector" /> </linearlayout>
and in fragment inflate above layout:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { linearlayout linear = (linearlayout) inflater.inflate(r.layout.swipe_screen_left, container, false); view = (listview) linear.getchildat(0); adapter = new customadapter(getactivity(), data, getfragmentmanager()); view.setadapter(adapter); return linear; }
Comments
Post a Comment