your content must have a listview whose id attribute is ' android.r.id.list ' . -


i write program when run program, program has runtime error :(

the error in logcat :

your content must have listview id attribute 'android.r.id.list' 

i set android:id="@android:id/list" in listview in activity_main.xml file.

i write code, please read , me .

mainactivity.java:

public class mainactivity extends listactivity {  private textview text; private static final string[] items={"test", "test1" , "test2" , "test3" , "test4" , "test5" , "test6"};  @override public void oncreate(bundle savedinstancestate){     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     setlistadapter(new arrayadapter<string>(this,r.layout.row,r.id.label,items));     text=(textview)findviewbyid(r.id.selection); } public void onlistitemclick(listview parent,view v,int position,long id){     text.settext(items[position]); } } 

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical">    <textview        android:id="@+id/selection"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>    <listview        xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@android:id/list"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:drawselectorontop="false"/> </linearlayout> 

row.xml :

<?xml version="1.0" encoding="utf-8"?> <linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="horizontal">    <imageview        android:id="@+id/pic"        android:padding="2dip"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/pic"/>    <textview        android:id="@+id/label"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/> </linearlayout> 

cheers.

compare code nothing difference....

enter image description here

mainactivity

package com.example.testdemo;  import android.annotation.suppresslint; import android.app.actionbar; import android.app.dialog; import android.app.listactivity; import android.os.bundle; import android.view.menu; import android.view.view; import android.widget.arrayadapter; import android.widget.listview; import android.widget.textview; import android.widget.toast;  public class mainactivity extends listactivity {      private textview text;     private static final string[] items = { "test", "test1", "test2", "test3",             "test4", "test5", "test6" };      @suppresslint("newapi")     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main_);            setlistadapter(new arrayadapter<string>(this, r.layout.lable,                 r.id.label, items));         text = (textview) findviewbyid(r.id.selection);      }      @override     protected void onlistitemclick(listview l, view v, int position, long id) {         // todo auto-generated method stub         text.settext("" + items[position]);         super.onlistitemclick(l, v, position, id);     }       } } 

activity_main.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >      <textview         android:id="@+id/selection"         android:layout_width="fill_parent"         android:layout_height="wrap_content" />      <listview          android:id="@android:id/list"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:drawselectorontop="false" />  </linearlayout> 

row.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="horizontal" >      <imageview         android:id="@+id/pic"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:padding="2dip"         android:src="@drawable/ic_launcher" />      <textview         android:id="@+id/label"         android:layout_width="fill_parent"         android:layout_height="wrap_content" />  </linearlayout> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -