listview - Cannot get Android tabs with swipable view to correctly pass information from one tab to another and display it correctly -
edit: @ankit aggarwal, got 1 part working, tab 1 not switching tab 2. still need assistance on view not refreshing in tab 2.
i working on app, in using tabs. based app on example found on internet here.
what have listview in tab 1. want happen when click on item in list, send id tab 2, want populate listview based on passed data. having issues getting work properly.
currently, have working if click item in list on tab 1, tab 2 data , populates new list, adds view on tab 2 instead of refreshing/overwriting/etc., , app not automatically switch new tab. have layout in tab 2 (i.e., receiving tab):
person.xml
<linearlayout android:id="@+id/person_information_layout"> <textview android:id="@+id/header_row" /> <linearlayout> <textview android:id="@+id/column1_row_header" /> <textview android:id="@+id/column2_row_header" /> <textview android:id="@+id/column3_row_header" /> </linearlayout> <listview android:id="@+row_of_data"></listview> </linearlayout>
i populating list in receiving tab (tab 2) adapterview , database cursor.
personinformation.java
package mypackage; public class personinformation extends fragment { private view rootview; private databasehelper mydbhelper; private cursor informationcursor; private simplecursoradapter mysimplecursoradapter; private textview personiddisplay; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate){ rootview = inflater.inflate(r.layout.person, container, false); personid = getarguments().getstring("personid"); mydbhelper = new databasehelper(getactivity()); informationcursor = mydbhelper.getinformationcursor(personid); string[] fromcolumns = {"firstname", "lastname", "homephone", "homeaddress"}; int[] toviews = {r.id.firstname_textview, r.id.lastname_textview, r.id.homephone_textview, r.id.homeaddress_textview}; mysimplecursoradapter = new simplecursoradapter(getactivity(), r.layout.person_information, informationcursor, fromcolumns, toviews, 0); personiddisplay = (textview) rootview.findviewbyid(r.id.header_row); personiddisplay.settext("person id: " + personid); listview mylistview = (listview) rootview.findviewbyid(r.id.row_of_data); mylistview.setadapter(mysimplecursoradapter); mydbhelper.close(); return rootview; } }
this person_information layout gets populated:
person_information.xml
<linearlayout> <textview android:id="@+id/column1_data" /> <textview android:id="@+id/column2_data" /> <textview android:id="@+id/column3_data" /> </linearlayout>
and here sending tab (tab 1)
home.java
package mypackage; public class home extends fragment { private view rootview; private databasehelper mydbhelper; private cursor personcursor; private simplecursoradapter mysimplecursoradapter; private activity myactivity; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate){ rootview = inflater.inflate(r.layout.home, container, false); mydbhelper = new databasehelper(getactivity()); personcursor = mydbhelper.getpersoncursor(); string[] fromcolumns = {"personid"}; int[] toviews = {r.id.person_id_textview}; mysimplecursoradapter = new simplecursoradapter(getactivity(), r.layout.person_layout, personcursor, fromcolumns, toviews, 0); listview mylistview = (listview) rootview.findviewbyid(r.id.person_row); mylistview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { cursor subcursor = (cursor) mysimplecursoradapter.getitem(position); string personidnumber = subcursor.getstring(subcursor.getcolumnindex("personid")); personinformation personinformation = new personinformation(); bundle mybundle = new bundle(); mybundle.putstring("personid", personidnumber); personinformation.setarguments(mybundle); getfragmentmanager().begintransaction().replace(r.id.person_information_layout, personinformation).commit(); } }); mylistview.setadapter(mysimplecursoradapter); mydbhelper.close(); return rootview; } }
as can see, have layout top information row, row of column headers, rows of data. want this:
top information row column headers data row 1 data row 2 ... data row n
currently, when click person in tab 1, tab 2 data tab 1 , populates new list correctly, draws under existing top information row , column headers, have layers:
top information row column headers top information row column headers data row 1 data row 2 ... data row n
also, tab not automatically switch tab 1 tab 2 when click row in tab 1.
instead of line in sending tab (tab 1)
getfragmentmanager().begintransaction().add(r.id.person_information_layout, personinformation).commit();
i changed line:
getfragmentmanager().begintransaction().add(r.id.row_of_data, personinformation).commit();
but got error:
"addview(view) not supported in adapterview"
from understand, cannot addview listview, changed parent of listview, duplicate view.
i keep coming wanting change line in receiving tab (tab 2) from
listview mylistview = (listview) rootview.findviewbyid(r.id.row_of_data);
to this
linearlayout mylinearlayout = (linearlayout) rootview.findviewbyid(r.id.person_information_layout);
but cursor adapter not work that.
what need working?
(1)
currently, when click person in tab 1, tab 2 data tab 1 , populates new list correctly, draws under existing top information row , column headers, have layers:
it happening because statement instead of switching tab2, adding new fragment on top of activity's frame.
getfragmentmanager().begintransaction().add(r.id.person_information_layout, personinformation).commit();
(2)
also, tab not automatically switch tab 1 tab 2 when click row in tab 1.
you using viewpager in tabs implementation. change tab2 can
viewpager.setcurrentitem(2);
note: missing here view pager automatically loads page previous , next 1 particular page. when in tab1, tab2 have been loaded. tab2 won't refresh when click on list item because have loaded.
Comments
Post a Comment