gpt4 book ai didi

android - 在android中的ListView的ItemClickListener上更改Imageview的图像

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

我正在使用自定义 ListView 来显示图像和文本,并且正在使用 Cursor。现在,onItemClickListener(),我想更改 ImageView 的图像,我还想更改 TextView 的 textColor。我想禁止该项目点击哪个用户 Click。我已经尝试了几件事,但都没有奏效。
这个怎么做 ?

XML 代码:

        <ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/queimg"
android:src="@drawable/ic_answer" />

<TextView
android:id="@+id/option"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="14dp"
android:layout_toRightOf="@+id/icon"
android:text="hello" />

Java 代码:

        final List<String> lstOption = new ArrayList<String>();

ArrayList<Map<String, String>> arrlist = new ArrayList<Map<String, String>>();

Map<String, String> m = null;
if (option != null) {
if (option.moveToFirst()) {
do {
lstOption.add(option.getString(option
.getColumnIndex("Option")));

m = new HashMap<String, String>();
m.put("option",
option.getString(option.getColumnIndex("Option")));

arrlist.add(m);
} while (option.moveToNext());
}
}

SimpleAdapter adapter = new SimpleAdapter(this, arrlist,
R.layout.topicwisequestion, new String[] { "option" },
new int[] { R.id.option });


lvTWOptions.setAdapter(adapter);
lvTWOptions.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});

最佳答案

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selection[position] = true;
((ImageView)view.findViewById(R.id.icon)).setImageResource(R.drawable.yourImageResourceId);
((TextView)view.findViewById(R.id.option)).setTextColor(Color.BLUE);
}

试试这段代码,希望它能有所帮助。

final boolean[] selection = new boolean[arrlist.length];
SimpleAdapter adapter = new SimpleAdapter(this, arrlist, R.layout.topicwisequestion, new String[] { "option" },new int[] { R.id.option }){
@Override
public boolean isEnabled(int position) {
return !(selection[position]);
}
}

关于android - 在android中的ListView的ItemClickListener上更改Imageview的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21908022/

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