Android-can';不要合并视图

Android-can';不要合并视图,android,android-layout,Android,Android Layout,我有一个活动,其中我尝试显示一些简单的消息,然后是一个项目列表。据我所知,我需要两个视图:一个用于简单布局,另一个用于适配器将处理的项目列表 这是我的密码: ArrayAdapter<SolutionTopic> adapter; ArrayList<SolutionTopic> problems = new ArrayList <SolutionTopic>( ); 阵列适配器; ArrayList problems=新的Array

我有一个活动,其中我尝试显示一些简单的消息,然后是一个项目列表。据我所知,我需要两个视图:一个用于简单布局,另一个用于适配器将处理的项目列表

这是我的密码:

ArrayAdapter<SolutionTopic> adapter;        

ArrayList<SolutionTopic> problems = new ArrayList <SolutionTopic>( );   
阵列适配器;
ArrayList problems=新的ArrayList();
/**在首次创建活动时调用*/ @凌驾 创建时的公共void(Bundle savedInstanceState) { super.onCreate(savedInstanceState)

//加载布局
setContentView(R.layout.solution);
SolutionTopic s=新的SolutionTopic();
s、 setSolutionTopicName(“你好”);
问题。添加(s);
适配器=新阵列适配器(此,R.layout.solution\u主题\u列表,
R.id.标签、问题);
TextView解决方案标题=(TextView)findViewById(R.id.solution\u标题);
TextView解决方案描述=(TextView)findViewById(R.id.solution\u描述);
setListAdapter(适配器);
}

下面是solution.xml

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

<TextView
    android:id="@+id/solution_title"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Label1"
    />  

<TextView
    android:id="@+id/solution_description"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Label2"
    />  

</LinearLayout>

下面是解决方案_topic _list.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:padding="10dp"
    android:textSize="16sp" >
</TextView>  

我不确定的是如何让这两个渲染在一起。理想情况下,我要做的是先显示TextView消息,然后显示项目列表

你知道我怎么做吗


谢谢

您不应该从solution.xml中删除ListView,在该ListView中将显示您的SolutionTopics

要了解全局,您的界面将有三个视图:

-text视图:@+id/解决方案\标题

-TextView:@+id/解决方案描述

-ListView:@android:id/list

ListView包含未定义数量的solution_topic_list.xml条目

PD:ArrayAdapter的第三个参数(R.id.label)应该是solution_topic_list.xml中TextView的id:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/label"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>  


您还应该在SolutionTopic类中实现toString方法,以获得所需的字符串。

您的活动是ListActivity的子类吗?当您开始您的活动时,您当前看到了什么?我有点困惑如何使这两个xml文件一起工作,以及如何在代码中正确调用它们。你能给我解释一下这一切是如何协同工作的吗?谢谢本文很好地解释了与ListView相关的所有内容:请仔细阅读。如果你不明白,在这里问:)太好了!!!!!也许你可以把你的另一个问题标记为已解决,然后给我赏金:D
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/label"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>