android - Calling ArrayList in Java -
hi im trying make code go through arraylist have in xml put them in tablelayout im having trouble calling arraylist xml
im trying somethin this
arraylist list = collection(r.array.arraylist); int total = list.size(); (int current = 0; current < total; current++) { // create tablerow , give id tablerow tr = new tablerow(this); tr.setid(100+current); tr.setlayoutparams(new layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); textview labeltv = new textview(this); labeltv.setid(200+current); labeltv.settext(list); labeltv.settextsize(dip, 14); labeltv.setgravity(gravity.center); labeltv.settextcolor(color.white); labeltv.setlayoutparams(new layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); tr.addview(labeltv); i dont think going through arraylist data , textview isnt displaying text please help
create table layout using java file or xml file
step1:(step 1 has 2 ways follow one)
/*create tablelayout in java no need create activity can handle in java file if u want xml file use or condition loop*/ tablelayout tablelayout=new tablelayout(this); tablelayout.setlayoutparams(new tablelayout.layoutparams(tablelayout.layoutparams.match_parent, tablelayout.layoutparams.match_parent)); setcontentview(tablelayout); /*follow java code add activity in manifest file go step 2*/ --------------------or--------------------
/create tablelayout in xml , getview in java/
xml:
<?xml version="1.0" encoding="utf-8"?> <tablelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/table" android:layout_width="match_parent" android:layout_height="match_parent"> </tablelayout> java:
setcontentview(r.layout.table_layout); tablelayout tablelayout= (tablelayout) findviewbyid(r.id.table); step2:
int colors[]=getresources().getintarray(r.array.value); list<string> str=new arraylist<string>(); collections.addall(str, getresources().getstringarray(r.array.arrayvalues)); log.d(tag,str.tostring()); for(int i=0;i<str.size();i++){ tablerow row=new tablerow(this); row.setid(101+i); row.setbackgroundcolor(color.black); row.setlayoutparams(new tablelayout.layoutparams(tablelayout.layoutparams.match_parent, tablelayout.layoutparams.match_parent)); textview text=new textview(this); text.setid(201+i); text.setlayoutparams(new tablerow.layoutparams(tablerow.layoutparams.wrap_content,tablerow.layoutparams.wrap_content)); text.settext(str.get(i)); text.setpadding(0,10,0,10); text.settextcolor(colors[i]); row.addview(text); tablelayout.addview(row); } strings.xml
<resources> <string-array name="arrayvalues"> <item>red</item> <item>orange</item> <item>yellow</item> <item>green</item> <item>blue</item> <item>indigo</item> <item>violet</item> </string-array> <integer-array name="value"> <item>@color/red</item> <item>@color/orange</item> <item>@color/yellow</item> <item>@color/green</item> <item>@color/blue</item> <item>@color/indigo</item> <item>@color/violet</item> </integer-array> </resources> colors.xml
<resources> <color name="red">#ff0000</color> <color name="orange">#ff7f00</color> <color name="yellow">#ffff00</color> <color name="green">#00ff00</color> <color name="blue">#0000ff</color> <color name="indigo">#4b0082</color> <color name="violet">#9400d3</color> </resources> output:
-------------------------------------------------------------------------finish------------------------------------------------
only getting array string.xml file(dont follow getting array string file)
arraylist<string> str=new arraylist<string>(); string[] val=getresources().getstringarray(r.array.value); str.addall(arrays.aslist(val)); log.d(tag,str.tostring()); 
Comments
Post a Comment