how to properly set the orientation of Table layout in android -


following code along xml file have 2 table layouts within 2 frame layouts. 1st table layout used set heading table while 2nd table used set rows dynamically in 2nd table layout though heading seems fitting rows dont align below heading may doing mistake in setting parameters table layout . in fix . appreciated. thank you.

package com.table; import android.app.activity; import android.graphics.bitmap; import android.graphics.color; import android.graphics.yuvimage; import android.os.bundle; import android.text.editable; import android.text.inputtype; import android.text.textwatcher; import android.util.log; import android.view.gravity; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.relativelayout.layoutparams; import android.widget.imageview; import android.widget.linearlayout; import android.widget.tablelayout; import android.widget.tablerow; import android.widget.textview; import java.util.list; public class tableactivity extends activity { tablelayout table,table_values; button scan,add; string value; edittext ed1; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); createtablelayout(); addrows(); scan = (button)findviewbyid(r.id.read); if(scan != null) { scan.setonclicklistener(new onclicklistener() { public void onclick(view v) { } }); } try { scan.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { setcontentview(r.layout.code); add=(button)findviewbyid(r.id.button2); } }); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } try { add.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { } }); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } } public void createtablelayout() { table = (tablelayout) findviewbyid(r.id.tablelayout1); // table.setbackgroundresource(r.drawable.sky); //tablerow tr_heading = new tablerow(this); table_values = (tablelayout) findviewbyid(r.id.tablelayout2); tablerow tr_heading = new tablerow(this); tr_heading.setid(10); tr_heading.setbackgroundcolor(color.gray); tr_heading.setlayoutparams(new layoutparams(layoutparams.match_parent,layoutparams.fill_parent)); textview serial = new textview(this); serial.setid(20); serial.settext("sr no. "); serial.settextcolor(color.black); tr_heading.addview(serial); // add column table row //textview label_question = new textview(this); textview name = new textview(this); name.setid(20); name.settext("id "); name.setwidth(40); name.settextcolor(color.black); tr_heading.addview(name); // add column table row //textview label_question = new textview(this); textview quantity = new textview(this); quantity.setid(20); quantity.settext(" quantity"); quantity.settextcolor(color.black); tr_heading.addview(quantity); // add column table row textview amt = new textview(this); amt.setid(20); amt.settext(" amt"); amt.settextcolor(color.black); tr_heading.addview(amt); table.addview(tr_heading, new tablelayout.layoutparams( layoutparams.match_parent, layoutparams.fill_parent)); } //--------------------------adding rows table -------------------------------------- public void addrows() { integer count = 0; (int count1 = 0; count1<3; count1++) { tablerow tr = new tablerow(this); if (count % 2 != 0) tr.setid(100 + count); tr.setclickable(true); tr.setlayoutparams(new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content)); textview sr = new textview(this); sr.settext("1"); //sr.setgravity(gravity.center ); sr.setpadding(2, 0, 5, 0); sr.settextcolor(color.white); sr.setclickable(true); tr.addview(sr); textview idval = new textview(this); idval.settext(value); idval.setgravity(gravity.center ); idval.settext(" fdfj"); idval.setpadding(2, 0, 5, 0); idval.settextcolor(color.white); idval.setclickable(true); tr.addview(idval); edittext quantity = new edittext(this); //quantity.setid(200 + count); quantity.setgravity(gravity.center ); quantity.settextcolor(color.black); // quantity.setlayoutparams(new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content)); // quantity.setwidth(1); quantity.settext("1"); quantity.setinputtype(inputtype.type_class_number); int val=integer.parseint((quantity.gettext().tostring())); // quantity.setheight(2); quantity.setenabled(true); quantity.setpadding(2,0,5,0); tr.addview(quantity); textview amount=new textview(this); amount.setgravity(gravity.center); amount.settextcolor(color.white); amount.setclickable(true); //amount.setlayoutparams(new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content)); amount.setenabled(true); //amount.settext(" 1000"); amount.settext(string.valueof(( val*10))); // amount.setwidth(1); // amount.setheight(2); tr.addview(amount); // add table row table_values.addview(tr, new tablelayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content)); count++; } } } **xml file below: <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <framelayout android:id="@+id/framelayout1" android:layout_height="match_parent" android:layout_width="match_parent"> <framelayout android:id="@+id/framelayout2" android:layout_height="match_parent" android:layout_margintop="40dp" android:layout_marginbottom="70dp" android:layout_width="match_parent"> <tablelayout android:layout_height="wrap_content" android:id="@+id/tablelayout1" android:layout_width="match_parent"> </tablelayout> <framelayout android:id="@+id/framelayout4" android:layout_width="match_parent" android:layout_height="match_parent"> <tablelayout android:layout_height="wrap_content" android:id="@+id/tablelayout2" android:layout_width="match_parent"> </tablelayout> </framelayout> </framelayout> <framelayout android:id="@+id/framelayout3" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_gravity="bottom"> <button android:text="scan" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp"> </button> <button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="button" android:layout_gravity="center_horizontal"> </button> </framelayout> </framelayout> </linearlayout> screen shot: http://i.stack.imgur.com/0nqsr.png ![this ther screen image[1] [1]: http://i.stack.imgur.com/0nqsr.png 

you have 2 framelayouts , overlap each other since not given makes them on beneath other.

anyway , recommend use single tablelayout , or listview , or gridlayout .

here's example of tablelayout:

http://wowjava.wordpress.com/2011/04/01/dynamic-tablelayout-in-android/


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -