gpt4 book ai didi

android - 如何制作带有复选框和图像的ListView?

转载 作者:行者123 更新时间:2023-11-29 16:16:10 25 4
gpt4 key购买 nike

我现在将此代码用于我的简单 ListView:

final ListView lv = (ListView)findViewById(R.id.apps_list);
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, myString.split("\n")));

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

}
});

和布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:id="@+id/separator_apps"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/apps" />


<ListView
android:id="@+id/apps_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/separator_apps" >

</ListView>

</RelativeLayout>

但是我需要在 THIS ListView 的每一行中添加 Image 和 CheckBox,有人能给我一个很好的例子吗?

最佳答案

您需要创建自己的自定义适配器来为每个项目加载 ImageView 和复选框组件,了解有关在 android 中创建自定义适配器的一些基础知识。

休息,您需要处理复选框,请参阅我之前的解决方案:

How to use checkbox in listview

关于android - 如何制作带有复选框和图像的ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9328113/

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