单项选择列表项不填充
问题描述:
我建立一个单一的选择清单,在底部的按钮,我似乎无法得到实际列表中显示的文本。基本上,这是一个简单的实现看起来像:单项选择列表项不填充
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)
...
}
和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的!
答
随着改变你的宽度,你应该增加:android:cacheColorHint="#00000000"
这里是一个链接,可能会有帮助:http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html
否则,当你滚动,你会得到黑盒和其他不想要的结果,当你滚动与你的名单。
使用'机器人:layout_width =“0dp”'用于'ListView'在垂直'LinearLayout'意味着宽度将字面上'0dp'如'机器人:layout_weight'只会影响到垂直尺寸。将'android:layout_width'设置为'fill_parent'。另外,你需要在调用'setListAdapter(...)'之前填写你的'ArrayAdapter'。 – Squonk
哇,我觉得很蠢;谢谢你的收获! – kousun12