Android Display a list using ListView -


i trying display list after clicking button on android.

this code:

//button after clicking should display list final button button4 = (button) findviewbyid(r.id.widget30); button4.setonclicklistener(new view.onclicklistener() {     public void onclick(view v) {          intent myintent = new intent(v.getcontext(), testlistactivities.class);         startactivity(myintent);      }      public class testlistactivities extends activity {         string[] listitems = {"game1", "game2",                                "game3", "game4"};         public listview la;          /** called when activity first created. */         @override         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.main2);             la=(listview)findviewbyid(r.id.widget50);             la.setadapter(new arrayadapter<string>(this,              r.layout.main2, listitems));         } } 

my xml file is:

?xml version="1.0" encoding="utf-8"? absolutelayout android:id="@+id/widget28" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"  listview android:id="@+id/widget50" android:layout_width="wrap_content" android:layout_height="wrap_content"   absolutelayoute 

but when click button, application forced close , crashes.

manifest file

<application android:icon="@drawable/icon" android:label="bam! pong" android:debuggable="true">   <activity android:name=".gui" android:label="@string/app_name" android:screenorientation="portrait"><intent-filter><action android:name="android.intent.action.main"></action> 

you seem use r.layout.main2 both activity layout (setcontentview(r.layout.main2);) , listview layout. (a.setadapter(new arrayadapter(this, r.layout.main2, listitems));) , not right way use listview, activity layout should layout contains listview, while layout giving arrayadapter should different layout containing views repeated each entry in list.

take @ api demos in android sdk, there several listview examples show how use listview.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -