Android ListView';s项目布局错误

Android ListView';s项目布局错误,android,listview,Android,Listview,我对列表视图项使用以下布局 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://scheme.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:

我对列表视图项使用以下布局

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://scheme.android.com/apk/res/android"
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:textSize="18sp"
    android:minHeight="40sp"
    />

但是我在logcat java.lang.RuntimeException中得到一个错误。。。必须提供布局宽度参数

我的main.xml是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget28"
    android:background="#ff000033"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="70px"
        android:layout_height="30px"
        android:paddingLeft="2px"
        android:paddingTop="2px"
        android:background="@drawable/ic_launcher"
     ></ImageView>

    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>

这是我的活动的onCreate代码

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    context=this.getApplicationContext();
    this.setTitle("NP Headline News");

    myListView=(ListView)findViewById(R.id.myListView);
    myListView.setOnItemClickListener(new OnItemClickListener(){

            @Override
        public void onItemClick(AdapterView<?> arg0, View v, int index,long id) {
                // TODO Auto-generated method stub
                String urlAddress=urlAddresses[index];
                String urlCaption = urlsCaptions[index];
            }

    });

  int layoutId=R.layout.simple_list_item_1;
   // int layoutId=android.R.layout.simple_list_item_1;
    aa = new ArrayAdapter<String>(this,layoutId,this.urlsCaptions);

    myListView.setAdapter(aa);
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
context=this.getApplicationContext();
本集标题(“NP头条新闻”);
myListView=(ListView)findViewById(R.id.myListView);
myListView.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView arg0,视图v,整数索引,长id){
//TODO自动生成的方法存根
字符串urlAddress=urlAddresses[索引];
字符串urlCaption=urlsCaptions[index];
}
});
int layoutId=R.layout.simple\u list\u item\u 1;
//int layoutId=android.R.layout.simple\u list\u item\u 1;
aa=新阵列适配器(this、layoutId、this.urlsCaptions);
myListView.setAdapter(aa);
}

我认为这与我的简单列表项有关,因为如果我使用android.R.layout.simple列表项,那么一切都正常

你应该将文本视图放在一个布局下,因为你使用的是一个独特的文本视图,你可以添加一个线性布局

<?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 xmlns:android="http://scheme.android.com/apk/res/android"
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:textSize="18sp"
    android:minHeight="40sp"
    />
</LinearLayout>

我想问题来自不同的方面

您正在执行自定义项目视图,但使用标准AdapterView

对于标准阵列适配器,您需要满足预期结构

或者,您可以构建自己的ArrayAdapter并提供专用的getView


以下是已清除错误的布局:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:textSize="18sp"
    android:minHeight="40sp"

    />
在上一行中,您错误地键入了
scheme
,而不是
schemas

这就是错误所在

因此,只有我提到,如果您查看代码时不使用out时态,您可以很容易地获得它

xmlns
表示名称空间,为了使
android:
前缀属性有价值,名称空间应该是适当的


希望您理解,答案对您有帮助。

您能发布完整的错误文本吗您确定RuntimeException引用了此布局吗?这似乎是正确的。。。请也粘贴listview布局。我认为可以添加单个Textview。是否有意义是另一个问题,尤其是某些属性可能是useless@PedroTeran:将
文本视图
放在
版面
内不是必须的。我们可以像他那样使用它。@Raza没问题,伙计。寒冷“在正文中添加910个字符”——真的吗?你找不到更好的描述吗?谈论和使用这种联系方式,因为我们没有私人信息系统。无论如何-建议编辑时,请正确执行。@ShadowWizard感谢您的建议。我在窗口中看不到我接受的默认描述。这就是我错过它的原因。此后,我不会这样描述它,我进一步的建议也不会是次要的。我会妥善处理的。谢谢你告诉我。没有恐吓,只是想帮助你更好地通过编辑。
xmlns:android="http://schemas.android.com/apk/res/android"