java - Freeze table row header to vertical scroll of table view -
i have activity in having table layout. table getting dynamically populated through activity.
as table horizontally long, ease user handling, have implemented horizontal scrolling table after s.no. column. s.no. column should not exposed horizontal scrolling ever , achieved.
the whole table vertically scrollable, what want freeze header row of table vertical scrolling, horizontal scrolling should present in header rows after s.no. column.
this activity code:
public class reportlistactivity extends activity { tablelayout srno_table; tablerow srno_report_tr_data; tablelayout report_table; tablerow report_tr_data; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_report_list); srno_table=(tablelayout) findviewbyid(r.id.srno_table); //---------------serial no table header----------------------------------------------- tablerow srno_tr_head = new tablerow(this); srno_tr_head.setid(10); srno_tr_head.setbackgroundcolor(color.gray); srno_tr_head.setlayoutparams(new layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); textview label_sr_no = new textview(this); label_sr_no.setid(20); label_sr_no.settext("s.no."); label_sr_no.settextcolor(color.white); label_sr_no.setpadding(5,5,5,5); srno_tr_head.addview(label_sr_no);// add column table row here label_sr_no.settextsize(20); srno_table.addview(srno_tr_head, new tablelayout.layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); //---------------serial no table header----------------------------------------------- report_table=(tablelayout) findviewbyid(r.id.report_table); //---------------report table header----------------------------------------------- tablerow report_tr_head = new tablerow(this); report_tr_head.setid(10); report_tr_head.setbackgroundcolor(color.gray); report_tr_head.setlayoutparams(new layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); textview label_test_name = new textview(this); label_test_name.setid(20); label_test_name.settext("test name"); label_test_name.settextcolor(color.white); label_test_name.setpadding(5,5,5,5); report_tr_head.addview(label_test_name);// add column table row here label_test_name.settextsize(20); textview label_test_date = new textview(this); label_test_date.setid(21);// define id must unique label_test_date.settext("date"); // set text header label_test_date.settextcolor(color.white); // set color label_test_date.setpadding(5,5,5,5); // set padding (if required) report_tr_head.addview(label_test_date); // add column table row here label_test_date.settextsize(20); textview label_ro = new textview(this); label_ro.setid(21);// define id must unique label_ro.settext("r.o."); // set text header label_ro.settextcolor(color.white); // set color label_ro.setpadding(5,5,5,5); // set padding (if required) report_tr_head.addview(label_ro); // add column table row here label_ro.settextsize(20); textview label_wo = new textview(this); label_wo.setid(21);// define id must unique label_wo.settext("w.o."); // set text header label_wo.settextcolor(color.white); // set color label_wo.setpadding(5,5,5,5); // set padding (if required) report_tr_head.addview(label_wo); // add column table row here label_wo.settextsize(20); textview label_lo = new textview(this); label_lo.setid(21);// define id must unique label_lo.settext("l.o."); // set text header label_lo.settextcolor(color.white); // set color label_lo.setpadding(5,5,5,5); // set padding (if required) report_tr_head.addview(label_lo); // add column table row here label_lo.settextsize(20); textview label_max = new textview(this); label_max.setid(21);// define id must unique label_max.settext("max."); // set text header label_max.settextcolor(color.white); // set color label_max.setpadding(5,5,5,5); // set padding (if required) report_tr_head.addview(label_max); // add column table row here label_max.settextsize(20); textview label_tm = new textview(this); label_tm.setid(21);// define id must unique label_tm.settext("t.m."); // set text header label_tm.settextcolor(color.white); // set color label_tm.setpadding(5,5,5,5); // set padding (if required) report_tr_head.addview(label_tm); // add column table row here label_tm.settextsize(20); textview label_rank = new textview(this); label_rank.setid(21);// define id must unique label_rank.settext("rank"); // set text header label_rank.settextcolor(color.white); // set color label_rank.setpadding(5,5,5,5); // set padding (if required) report_tr_head.addview(label_rank); // add column table row here label_rank.settextsize(20); report_table.addview(report_tr_head, new tablelayout.layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); //---------------serial no table header----------------------------------------------- //--------------------sr no table body--------------------------- (int i=1; i<=10; i++) { srno_report_tr_data = new tablerow(this); srno_report_tr_data.setid(10); srno_report_tr_data.setbackgroundcolor(color.transparent); srno_report_tr_data.setlayoutparams(new layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); final textview sr_no = new textview(this); sr_no.setid(20); sr_no.settext(""+i); sr_no.settextcolor(color.black); sr_no.setpadding(5,5,5,5); srno_report_tr_data.addview(sr_no);// add column table row here srno_table.addview(srno_report_tr_data, new tablelayout.layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); //----------------------on click table row--------------------------------------- srno_report_tr_data.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub // toast.maketext(getapplicationcontext(), test_name.gettext().tostring(), toast.length_long).show(); // toast.maketext(getapplicationcontext(), test_date.gettext().tostring(), toast.length_long).show(); // toast.maketext(getapplicationcontext(), sr_no.gettext().tostring(), toast.length_long).show(); //toast.maketext(getapplicationcontext(), test_exam_set.gettext().tostring(), toast.length_long).show(); // intent intent = new intent(reportlistactivity.this, reportlistdetailsactivity.class); // finish(); // reportlistactivity.this.startactivity(intent); } }); //----------------------on click table row--------------------------------------- } //--------------------sr no table body table body--------------------------- //=================report table body============================ (int i=1; i<=10; i++) { report_tr_data=new tablerow(this); report_tr_data.setid(10); report_tr_data.setbackgroundcolor(color.transparent); report_tr_data.setlayoutparams(new layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); final textview test_name = new textview(this); test_name.setid(20); test_name.settext("speed test 60(min) demo-st-01"); test_name.settextcolor(color.black); test_name.setpadding(5,5,5,5); report_tr_data.addview(test_name);// add column table row here final textview test_date = new textview(this); test_date.setid(21);// define id must unique test_date.settext("12 mar 2013"); // set text header test_date.settextcolor(color.black); // set color test_date.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_date); // add column table row here final textview test_ro = new textview(this); test_ro.setid(21);// define id must unique test_ro.settext("2"); // set text header test_ro.settextcolor(color.black); // set color test_ro.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_ro); // add column table row here final textview test_wo = new textview(this); test_wo.setid(21);// define id must unique test_wo.settext("3"); // set text header test_wo.settextcolor(color.black); // set color test_wo.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_wo); // add column table row here final textview test_lo = new textview(this); test_lo.setid(21);// define id must unique test_lo.settext("85"); // set text header test_lo.settextcolor(color.black); // set color test_lo.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_lo); // add column table row here final textview test_max = new textview(this); test_max.setid(21);// define id must unique test_max.settext("101"); // set text header test_max.settextcolor(color.black); // set color test_max.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_max); // add column table row here final textview test_tm = new textview(this); test_tm.setid(21);// define id must unique test_tm.settext("-1.5"); // set text header test_tm.settextcolor(color.black); // set color test_tm.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_tm); // add column table row here final textview test_rank = new textview(this); test_rank.setid(21);// define id must unique test_rank.settext("5810"); // set text header test_rank.settextcolor(color.black); // set color test_rank.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_rank); // add column table row here final textview test_exam_set = new textview(this); test_exam_set.setid(21);// define id must unique test_exam_set.settext("123456"); // set text header test_exam_set.settextsize((float) 0.01); test_exam_set.settextcolor(color.transparent); // set color test_exam_set.setpadding(5,5,5,5); // set padding (if required) report_tr_data.addview(test_exam_set); // add column table row here report_table.addview(report_tr_data, new tablelayout.layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); //----------------------on click table row--------------------------------------- report_tr_data.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub toast.maketext(getapplicationcontext(), test_name.gettext().tostring(), toast.length_long).show(); // toast.maketext(getapplicationcontext(), test_date.gettext().tostring(), toast.length_long).show(); // toast.maketext(getapplicationcontext(), sr_no.gettext().tostring(), toast.length_long).show(); toast.maketext(getapplicationcontext(), test_exam_set.gettext().tostring(), toast.length_long).show(); // intent intent = new intent(reportlistactivity.this, reportlistdetailsactivity.class); // finish(); // reportlistactivity.this.startactivity(intent); } }); //----------------------on click table row--------------------------------------- } //=================report table body============================ } //onclick device button @override public void onbackpressed() { // on back. intent intent = new intent(reportlistactivity.this, taketestactivity.class); finish(); reportlistactivity.this.startactivity(intent); return; } //method show toast message public void makeatoast(string str) { //yet implement toast toast = toast.maketext(this,str, toast.length_short); toast.setgravity(gravity.center, 0, 0); toast.show(); } //saving value in preference variable public void saveinpreference(string name, string content) { sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this); sharedpreferences.editor editor = preferences.edit(); editor.putstring(name,content); editor.commit(); } //getting content preferences public string getfrompreference(string variable_name) { string preference_return; sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this); preference_return = preferences.getstring(variable_name,""); return preference_return; } }
the layout file:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".reportlistactivity" > <scrollview android:id="@+id/scrollview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignparentleft="true" android:layout_alignparenttop="true" > <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" > <relativelayout android:id="@+id/relativelayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_centervertical="true" > <tablelayout android:id="@+id/srno_table" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" > </tablelayout> </relativelayout> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/relativelayout1" > <horizontalscrollview android:id="@+id/horizontalscrollview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/relativelayout1" > <tablelayout android:id="@+id/report_table" android:layout_width="match_parent" android:layout_height="match_parent" > </tablelayout> </horizontalscrollview> </relativelayout> </relativelayout> </scrollview> </relativelayout>
p.s.: changes implemented in existing code.
you can refer this clarification
thanks in advance!
Comments
Post a Comment