我有个问题。我需要根据选中/未选中的复选框更改 listView 项目中的图像。如果选中复选框,我会放置一个图像,如果另一个图像是假的。
//代码
公共类 MainActivity 扩展 Activity {
String text = "default text";
int[] imgInt = new int[]{
R.drawable.navigation_accept,
R.drawable.ic_launcher
};
CheckBox chBox;
ImageView imageView;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chBox = (CheckBox) findViewById(R.id.list_item_checkbox);
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<1;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("text", text);
hm.put("imgInt", Integer.toString(imgInt[i]) );
aList.add(hm);
}
String[] from = { "text","imgInt"};
int[] to = { R.id.list_item_text,R.id.list_item_icon};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.item_item, from, to);
listView = ( ListView ) findViewById(R.id.countryLV);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
//代码