gpt4 book ai didi

Android ListView ,希望在我的 ListView 的每一行上有不同的图片

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

我正在尝试为每个列出的项目制作一个具有不同图像和文本的列表框。我尝试创建两个 setListAdapter,一个用于要显示的文本字符串,另一个用于图像名称。它没有用,我假设还有另一种方法可以做到这一点。

列表中的 CTICTY 类

public class cFashions extends ListActivity  {
TextView selection;
// list to fill list box wi*/
/*
String[] items={"CASUAL","DR ESSES","CAREER","OUTWEAR","FOOTWEAR",
"JEWELRY","ACCESSORIES"};
*/
String[] items={"CASUAL"};
String[] icons={"icon"};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fashions);

setListAdapter(new ArrayAdapter<String>(this,
R.layout.row, R.id.label,
items));

setListAdapter(new ArrayAdapter<String>(this,
R.layout.row, R.id.icon,
icons));
selection=(TextView)findViewById(R.id.selection);
}
}

列表中每个单元格布局的 XML 文件

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

<ImageView
android:id="@+id/icon"
android:layout_width="22px"
android:paddingLeft="2px"
android:paddingRight="2px"
android:paddingTop="2px"
android:layout_height="wrap_content"

/>

<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
/>
</LinearLayout>

泰德

最佳答案

您需要使用一个适配器,而不是两个,适配器知道如何处理您的 TextViewImageViewHere is a free excerpt摘 self 的一本书,其中详细介绍了这个主题。

关于Android ListView ,希望在我的 ListView 的每一行上有不同的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5214641/

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