Getting position of TextView in TableLayout Android -
i have table layout in android. set time table , looks following :
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fadescrollbars="false" > <tablelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/table" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchcolumns="*" > <tablerow android:id="@+id/tablerow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/blank" android:background="@drawable/border" /> <textview android:id="@+id/mon" android:background="@drawable/border" android:text="@string/monday" /> <textview android:id="@+id/tues" android:background="@drawable/border" android:text="@string/tuesday" /> <textview android:id="@+id/wed" android:background="@drawable/border" android:text="@string/wednesday" /> <textview android:id="@+id/thurs" android:background="@drawable/border" android:text="@string/thursday" /> <textview android:id="@+id/fri" android:background="@drawable/border" android:text="@string/friday" /> <textview android:id="@+id/sat" android:background="@drawable/border" android:text="@string/saturday" /> <textview## heading ## android:id="@+id/sun" android:background="@drawable/border" android:text="@string/sunday" /> </tablerow> <tablerow android:id="@+id/tablerow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/nine" android:background="@drawable/border" android:text="@string/nine" /> <textview android:id="@+id/nineone" android:background="@drawable/border" /> <textview android:id="@+id/ninetwo" android:background="@drawable/border" /> <textview android:id="@+id/ninethree" android:background="@drawable/border" /> <textview android:id="@+id/ninefour" android:background="@drawable/border" /> <textview android:id="@+id/ninefive" android:background="@drawable/border" /> <textview android:id="@+id/ninesix" android:background="@drawable/border" /> <textview android:id="@+id/nineseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/ten" android:background="@drawable/border" android:text="@string/ten" /> <textview android:id="@+id/tenone" android:background="@drawable/border" /> <textview android:id="@+id/tentwo" android:background="@drawable/border" /> <textview android:id="@+id/tenthree" android:background="@drawable/border" /> <textview android:id="@+id/tenfour" android:background="@drawable/border" /> <textview android:id="@+id/tenfive" android:background="@drawable/border" /> <textview android:id="@+id/tensix" android:background="@drawable/border" /> <textview android:id="@+id/tenseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow4" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/eleven" android:background="@drawable/border" android:text="@string/eleven" /> <textview android:id="@+id/elevenone" android:background="@drawable/border" /> <textview android:id="@+id/eleventwo" android:background="@drawable/border" /> <textview android:id="@+id/eleventhree" android:background="@drawable/border" /> <textview android:id="@+id/elevenfour" android:background="@drawable/border" /> <textview android:id="@+id/elevenfive" android:background="@drawable/border" /> <textview android:id="@+id/elevensix" android:background="@drawable/border" /> <textview android:id="@+id/elevenseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow5" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/twelve" android:background="@drawable/border" android:text="@string/twelve" /> <textview android:id="@+id/twelveone" android:background="@drawable/border" /> <textview android:id="@+id/twelvetwo" android:background="@drawable/border" /> <textview android:id="@+id/twelvethree" android:background="@drawable/border" /> <textview android:id="@+id/twelvefour" android:background="@drawable/border" /> <textview android:id="@+id/twelvefive" android:background="@drawable/border" /> <textview android:id="@+id/twelvesix" android:background="@drawable/border" /> <textview android:id="@+id/twelveseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow6" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/one" android:background="@drawable/border" android:text="@string/one" /> <textview android:id="@+id/oneone" android:background="@drawable/border" /> <textview android:id="@+id/onetwo" android:background="@drawable/border" /> <textview android:id="@+id/onethree" android:background="@drawable/border" /> <textview android:id="@+id/onefour" android:background="@drawable/border" /> <textview android:id="@+id/onefive" android:background="@drawable/border" /> <textview android:id="@+id/onesix" android:background="@drawable/border" /> <textview android:id="@+id/oneseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow7" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/two" android:background="@drawable/border" android:text="@string/two" /> <textview android:id="@+id/twoone" android:background="@drawable/border" /> <textview android:id="@+id/twotwo" android:background="@drawable/border" /> <textview android:id="@+id/twothree" android:background="@drawable/border" /> <textview android:id="@+id/twofour" android:background="@drawable/border" /> <textview android:id="@+id/twofive" android:background="@drawable/border" /> <textview android:id="@+id/twosix" android:background="@drawable/border" /> <textview android:id="@+id/twoseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow8" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/three" android:background="@drawable/border" android:text="@string/three" /> <textview android:id="@+id/threeone" android:background="@drawable/border" /> <textview android:id="@+id/threetwo" android:background="@drawable/border" /> <textview android:id="@+id/threethree" android:background="@drawable/border" /> <textview android:id="@+id/threefour" android:background="@drawable/border" /> <textview android:id="@+id/threefive" android:background="@drawable/border" /> <textview android:id="@+id/threesix" android:background="@drawable/border" /> <textview android:id="@+id/threeseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow9" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/four" android:background="@drawable/border" android:text="@string/four" /> <textview android:id="@+id/fourone" android:background="@drawable/border" /> <textview android:id="@+id/fourtwo" android:background="@drawable/border" /> <textview android:id="@+id/fourthree" android:background="@drawable/border" /> <textview android:id="@+id/fourfour" android:background="@drawable/border" /> <textview android:id="@+id/fourfive" android:background="@drawable/border" /> <textview android:id="@+id/foursix" android:background="@drawable/border" /> <textview android:id="@+id/fourseven" android:background="@drawable/border" /> </tablerow> <tablerow android:id="@+id/tablerow10" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/five" android:background="@drawable/border" android:text="@string/five" /> <textview android:id="@+id/fiveone" android:background="@drawable/border" /> <textview android:id="@+id/fivetwo" android:background="@drawable/border" /> <textview android:id="@+id/fivethree" android:background="@drawable/border" /> <textview android:id="@+id/fivefour" android:background="@drawable/border" /> <textview android:id="@+id/fivefive" android:background="@drawable/border" /> <textview android:id="@+id/fivesix" android:background="@drawable/border" /> <textview android:id="@+id/fiveseven" android:background="@drawable/border" /> </tablerow> </tablelayout> </scrollview>
when user clicks on cell in app wanting able position of exact cell have clicked. get column id unable full position. code following
public class timetable extends activity { textview tv; tablerow row; string dayname; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_time_table); tablelayout group = (tablelayout) findviewbyid(r.id.table); row = (tablerow) group.getchildat(0); (int = 0; < group.getchildcount(); i++) { row = (tablerow) group.getchildat(i); (int j = 0; j < row.getchildcount(); j++) { tv = (textview) row.getchildat(j); registerforcontextmenu(tv); tv.setid(j); tv.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub toast toast = toast.maketext(getapplicationcontext(), integer.tostring(v.getid()), toast.length_long); toast.show(); } }); } } }
anyone know how can full position? thanks
suggestion : can position of cell using loop iterating. iterates reaches every new cell specific column , row. work you.
tablelayout group = (tablelayout) findviewbyid(r.id.table); row = (tablerow) group.getchildat(0); (int = 0; < group.getchildcount(); i++) { row = (tablerow) group.getchildat(i); (int j = 0; j < row.getchildcount(); j++) { tv = (textview) row.getchildat(j); registerforcontextmenu(tv); tv.setid(j); tv.setonclicklistener(onclick(tv,i,j)); } } view.onclicklistener onclick(final textview tc,final int row,final int col) { return new view.onclicklistener() { public void onclick(view v) { @override public void onclick(view v) { // todo auto-generated method stub //use col , row position of cell together. toast toast = toast.maketext(getapplicationcontext(), integer.tostring(v.getid()), toast.length_long); toast.show(); } });
Comments
Post a Comment