【问题标题】:Single Choice List Item Does not Populate单选列表项不填充
【发布时间】: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


【解决方案1】:

除了改变你的宽度,你应该添加:android:cacheColorHint="#00000000"

这是一个可能有帮助的链接:http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html

否则,当您滚动列表时,您会看到黑框和其他不需要的结果。

【讨论】:

    猜你喜欢
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 2013-01-10
    相关资源
    最近更新 更多