【发布时间】:2012-07-03 06:07:13
【问题描述】:
我正在构建一个底部带有按钮的单选列表,但我似乎无法显示实际列表中的文本。基本上,它是一个简单的实现,如下所示:
public class SetPrefsActivity extends ListActivity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.radiolist);
ArrayList<Hall> listItems = new ArrayList<Hall>();
ArrayAdapter<Hall> ar = new ArrayAdapter<Hall>(this, android.R.layout.simple_list_item_single_choice, listItems);
setListAdapter(ar);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{ ... //stuff});
...
//((ArrayAdapter<Hall>)getListAdapter()).add(stuff)
...
}
Radiolist 的 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="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="0dp"
android:drawSelectorOnTop="false"
/>
<Button
android:id="@+id/theButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to go to next Activity"
/>
</LinearLayout>
我看到的是列表应该去的黑色区域,然后是我的按钮。在我添加之前:setContentView(R.layout.radiolist); 它显示了填充列表就好了。如何让它显示在此布局中?
对不起,我刚接触安卓!
【问题讨论】:
-
将
android:layout_width="0dp"用于垂直ListView中的LinearLayout意味着宽度实际上是0dp,因为android:layout_weight只会影响垂直尺寸。将android:layout_width设置为fill_parent。此外,您需要在拨打setListAdapter(...)之前填写您的ArrayAdapter。 -
哇,我觉得自己很愚蠢;谢谢你的收获!
标签: android listview layout radio-button