android - adding view elements within a tablerow -


i have screen has tablelayout defined in xml 3 stretch columns. in code populating table rows inside tablelayout based on backend data fetched @ runtime. want create action wherein clicking tablerow, details data shown expanding table row. , clicking tabelrow again, data should collapsed. have tried using code below, not working , don't tablerow details data displayed/expanded after click. appreciated.

main.xml below

    <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="com.bfp.quiztemplate.scoresactivity" >  <scrollview     android:id="@+id/scrollview1"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_above="@+id/button1"     android:layout_below="@+id/quizspinner" >      <tablelayout         android:id="@+id/displayscorestable"         android:layout_width="fill_parent"         android:stretchcolumns="0,1,2"         android:layout_weight="1"         android:layout_height="wrap_content">      </tablelayout>     </scrollview> 

my activity class below

      tablelayout  tl = (tablelayout) findviewbyid(r.id.displayscorestable);         (int = 0; i<dataarray.length; i++){              tablerow tr = new tablerow(this);              tr.setbackgroundresource(r.drawable.cell_shape_scores);              tr.setlayoutparams(new layoutparams(layoutparams.match_parent,layoutparams.wrap_content));                  //add more view elelemtns inside tablerow             textview mytext = new textview(this);             mytext.settext ("test");             layoutparams textviewlayoutparams = new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content);                 mytext .setlayoutparams(textviewlayoutparams);                 tr.addview(mytext );               //now code expand/collpase logic               tr.settag(rowcount);              tr.setid(rowcount);                  tr.setonclicklistener(new view.onclicklistener(){                  public void onclick(view v) {                    rowcount = (integer) v.gettag();                    textview tv1 = new textview(scoresactivity.this);                    textview tv2=new textview(scoresactivity.this);                    tablerow.layoutparams trparams = new tablerow.layoutparams(tablerow.layoutparams.wrap_content, tablerow.layoutparams.wrap_content);                    tv1.setlayoutparams(trparams);                    tv2.setlayoutparams(trparams);                    tv1.settext("hello1!");                    tv2.settext("hello2!");                    tablerow trow = new tablerow(scoresactivity.this);                    trow.setlayoutparams(trparams);                    trow.addview(tv1);                    trow.addview(tv2);                    tablerow currentrow = (tablerow)findviewbyid(rowcount);                    currentrow .addview(trow);               }});        tl.addview(tr, new tablelayout.layoutparams(layoutparams.match_parent,layoutparams.wrap_content)); } 

i able solve using addview(tablerow, index) property of tablelayout. expanding had add many rows @ tat position , remove them collapsing.


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 -