gpt4 book ai didi

android - 显示空列表的 SimpleAdapter

转载 作者:行者123 更新时间:2023-11-29 01:43:20 26 4
gpt4 key购买 nike

代码编译没有错误,但结果在我的手机上只是一个空列表。那么问题是什么?这是我在 Activity 中的 onCreate 方法

    super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView;
ArrayList<HashMap<String, String>> list=new ArrayList<HashMap<String, String>>();
HashMap<String, String> m;
for(int i=0; i<=10; i++) {
m=new HashMap<String, String>();
m.put("key", "value"+i);
list.add(m);
}
String[] from={"key"};
int[] to={R.id.text1};
ListView lv=(ListView)findViewById(R.id.listView);
SimpleAdapter sa=new SimpleAdapter(this, list, R.layout.row, from, to);
lv.setAdapter(sa);

主.xml:

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

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/listView"
/>
</LinearLayout>

行.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="0px" android:layout_height="fill_parent"
android:id="@+id/text1"
android:text="dddddddd"
/>
</LinearLayout>

最佳答案

row.xml中,更改

<TextView android:layout_width="0px" android:layout_height="fill_parent"

<TextView android:layout_width="wrap_content" android:layout_height="fill_parent"

0px 的宽度将使 View 不可见,只能与 layout_weight 一起使用

关于android - 显示空列表的 SimpleAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23021446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com