开发者

ListView exception for Images + Text

I am trying to create a simple Icon+Text ListView but it does not work. I am using 2.1 Android SDK.

My main class is very small slightly modified from the tutorial:

public class Stuffs extends ListActivity {
    static final String[] COUNTRIES = new String[] {"A", "B","C"};

    /** Called when the acti开发者_StackOverflowvity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        

        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.title, COUNTRIES));


    }
}

and my list_item.xml file is this:

<?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/icon"        
        android:src="@drawable/icon" />


    <TextView       
        android:id = "@+id/title"
        android:padding="10dp"
        android:textSize="16sp" >
    </TextView>
</LinearLayout>

I have also created a "drawable" directory in my res directory and copied a "icon.png" into it.

But any time I try to run this the application hangs up unexpected in my android emulator. Am I missing something?


I found an excellent example of how to create lists with icons here: http://commonsware.com/Android/excerpt.pdf

The The Busy Coder's Guide to Android Development book in general is very enlightening.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜