2011-06-28 72 views
1

我正在尝试创建一个行布局,其中每个列表项都有一个要遵循的模板。目前我有这个,它允许我在每个列表中显示一行文本。Android XML布局问题

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:textSize="20sp" 
    android:padding="100dp" > 
</TextView> 

然而,当我试图改变它,让我增加更多的项目,如图像按钮和更多的文本字段,它总是不允许我进行编译。

我试着developer.android的网站是拿一块XML从一个教程,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<TextView android:id="@+id/text1" 
    android:textSize="16sp" 
    android:textStyle="bold" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 

<TextView android:id="@+id/text2" 
    android:textSize="16sp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 
</LinearLayout> 

但它引发了我的错误,说明 - 处理指令目标匹配“[XX] [MM] [11] “不允许 。 - 错误:解析XML错误:XML或文本声明不在实体的开始

有人可以帮助我吗?我不太确定这个错误的含义。

UPDATE:

什么,我试图做的是有像右侧的边栏,显示的项目清单,与我张贴的第一个XML片段,我能拿到我想要的结果,但我无法对其进行任何更改。

package com.project.test; 

import android.app.ListFragment; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class TestListFragment extends ListFragment { 

    String [] Items = {"Item A", "Item B", "Item C"}; 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
     setListAdapter(new ArrayAdapter<String>(getActivity(), 
       R.layout.listtemplate, Items)); 
    } 

    @Override 
    public void onListItemClick(ListView l, View v, int position, long id) { 
     Log.i("FragmentList", "Item clicked: " + id); 
    } 
} 
+0

不更新你的问题,使它成为完全不同的一个。马兹的回答是100%正确的,现在它是多余的。你应该已经标记了它的答案并开始了一个新的问题。 – Blundell

回答

2

可能是因为您缺少LinearLayout的开始标记?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 

<TextView android:id="@+id/text1" 
    android:textSize="16sp" 
    android:textStyle="bold" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 

<TextView android:id="@+id/text2" 
    android:textSize="16sp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 
</LinearLayout> 
+0

感谢您的回复,这解决了xml抛出错误的问题,但现在它会抛出一个非法的状态,为什么会这样呢? –

+0

嗨简化,我敢肯定,异常没有任何关系的XML文件。但尝试粘贴它,我们可以看到。 –

+0

感谢您的耐心等待,我使用片段内的代码更新了问题。 –

21

你不会相信,要解决这个...我有同样的问题,答案是“删除所有的空格之前启动XML第一线”

+1

+1我在xml声明之前插入了一条评论(<! - Some Comment-- >这是我的情况的问题和linearLayout – AgentKnopf

+1

失踪结束标记我相信你:) – Vaibs