刚开始接触手机开发 编写一个可以显示名单的列表 代码如下 但是问题在运行时总是出错 求各位大神指导
package com.YYD3;import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;public class YYD3 extends ListActivity {

String[] items={"One","Two","Three","Four","Five","Six","Serven"};
    /** Called when the activity is first created. */ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        setContentView(R.layout.main);          
        setListAdapter(new ArrayAdapter<String>(this,R.layout.test,items));
}   
    
}
main.XML:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp">
<ListView
android:id="@+id/lv"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:drawSelectorOnTop="false"
/>
<TextView  
android:id="@+id/tv"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>test.xml:<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/myitem"
  android:textStyle="normal"
  android:textSize="20sp"
  android:layout_width="fill_parent"
  android:layout_height="48sp"
  android:gravity="center_vertical"
  android:padding="8dip">
</TextView>

解决方案 »

  1.   

    你把test.xml放在一个布局里啊 。<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
    <TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/myitem"
      android:textStyle="normal"
      android:textSize="20sp"
      android:layout_width="fill_parent"
      android:layout_height="48sp"
      android:gravity="center_vertical"
      android:padding="8dip">
    </TextView>
    </LinearLayout>
      

  2.   

    具体什么错误呀,先把item放到布局试试吧
      

  3.   

    text.xml   那个顶层可以直接放 TextView 吗?
      

  4.   

    main.XML:
    那个textview最后少个textview结尾符吧……
      

  5.   

    这代码还算少,要是有几千行太吗,lz也不知道那个地方出错了,lz还这样贴出来么?
    还是希望lz吧问题贴出来,这样定位问题就比较容易了,OK
      

  6.   

    我也不清楚 我编译是OK的 但是在运行时程序就报 stop unexpectedly 所以来求救
      

  7.   

    这个是对于LISTVIEW控件使用的 不需要布局的吧