java - Android Studio (Referencing Objects) -


a former vb6 programmer starting out android studio.

i'm trying reference itemlist on layout. in vb i'd me.itemlist or thisform.itemlist

but know myactivity.xml.itemlist won't it. how can reference itemlist control?

sorry such noob question... first time around!

code in activity_my.xml file:

<listview      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/itemlist"     android:layout_centervertical="true"     android:layout_alignright="@+id/textview"     android:layout_alignend="@+id/textview" /> 

what need associate adapter. won't work:

arrayadapter<string> myadapter=new  arrayadapter<string>(  this,  android.r.layout.simple_list_item_1,       mystringarray); 

my issue, namely, android.r.layout.simple_list_item_1 not way reference listview object in myactivity.xml file in android studio. keep getting "cannot resolve symbol 'r'" error.

could please clue me in?

thanks!!!

you have use findviewbyid() method inherited appcompatactivity class. call list views setadapter method.

  listview listview = (listview) findviewbyid(r.id.'the id-name of list view');   listview.setadapater(myadapter); 

the arrayadapter takes 3 parameters in it's constructor. first context have provided 'this', works because activities subclasses of context class.

the second parameter supplied; android.r.layout.simple_list_item_1. format listview, e.g. have checkboxes next list items if liked using android, android.r.layout.simple_list_item_checked.

the third array, values @ each index of array used in list view.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -