保持图像中的GridView选择 [英] Keep image in GridView selected
问题描述
我所做的:
您好,大家好, 我有一个GrindView,我充满了我的数据库。现在,图像显示那里,都是滚动的。但是,当我点击它,他们不保持选中。要查看该图片被选定我建造了一座Toastmessage这表明我,我点击了与onIemClickListner什么图片。
Hello Guys, I've got a GrindView which i filled over my Database. Now the Images shows up there and are scrollable. But when I click on it, they don't keep selected. To see which picture is selected I builded a Toastmessage which shows me what picture i clicked on with the onIemClickListner.
问:
我想,让被点击的图片,选择。所以,你点击的时间在GridView的一个形象,之后就一直选择。 我如何能实现呢?我会很高兴,如果有一个教程或codeSAMPLE,来看看它是如何工作的。
I'd like to let the Clicked Image, selected. So that you click on time on a Image in the GridView and afterwards it keeps selected. How can i realize that? I would be happy if there's a tutorial or a codesample, to see how it works.
的code
这就是我想,只有实际的形象得到不断选择的颜色,但它不到风度工作的正确方法,有时它只是改变了。
This is what i tried that only the actual image gets keeps selected with the colors but it dosn't work the right way, sometimes it just changes..
//Hier wird gemerkt welches bild
gridview.setOnItemClickListener(new OnItemClickListener() {
boolean color = false;
View old;
View v;
public void onItemClick(AdapterView<?> parent, View vv, int position, long id) {
Toast.makeText(SFilterConfigActivity.this, "" + position, Toast.LENGTH_SHORT).show();
v = vv;
//gridview.setSelection(position);
if (color == false){
v.setBackgroundColor(0xFF00FF00);
old = v;
color = true;
}
else {
old.setBackgroundColor(0x00000000);
v.setBackgroundColor(0xFF00FF00);
color = false;
}
}
});
THX为你提前anwser
Thx for you anwser in advance
野生动物园
推荐答案
在调用setAdapter()
After you call setAdapter()
像这样
setSelection(的setSelected,真)
setSelection(setSelected, true)
这篇关于保持图像中的GridView选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!