) = ListView
의 행에서 해당 이미지를 설정하는 또 다른 옵션을 tuts 많이되어 있고 또한 사용 a SimpleAdapter.ViewBinder
. 행 뷰의 데이터를 설정하는 방법을 모르겠다 (from
및 to
배열에있는 것을 볼 수 없다) 또는 application.distanceList
에 무엇을 가지고 있는가? 여기에 작은 예제가있다. (A ListView
행에 상당) application.distanceList
각 Map
에서 먼저이 같은 항목을 추가해야합니다 :
이
map.put("position", "x"); // where x is the list row number(for the first Map in application.distanceList x will be 0, for the second Map in application.distanceList x will be 1 etc)
당신은 from
배열의 "position"
포함이 "position"
에 해당하는 것입니다 당신 ImageView
의 ID를 to
배열의 행 레이아웃에서 가져옵니다.
다음, 당신은 ListView
행의 이미지 (이것은 ListView
의 재생 메커니즘을 처리합니다)에 결합하는 SimpleAdapter.ViewBinder
를 추가해야합니다 :
mAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
// view is the ImageView from the row layout
// data is the x from the position column
if (view.getId() == R.id.imageView1) {
Integer rowNumber = Integer.parseInt((String) data);
// below is the explanation for mImageIds
((ImageView) view).setImageResource(mImageIds[rowNumber]);
return true;
}
return false;
}
});
mImageIds
하는 ints
의 배열입니다 것입니다 ListView
의 행에 대한 드로어 블의 ID를 누르고 마지막으로
// a field in your class
private int[] mImageIds = new int[8]; // you said you had 8 rows
//.. in the onCreate method initialize the mImageIds array
for (int j = 0; j < 8; j++) {
mImageIds[j] = R.drawable.ic_launcher;// a default image(you could use android.R.color.transparent for empty)
}
을 onItemClick
콜백 :
public void onItemClick(AdapterView<?> arg0, View v, int arg2,
long arg3) {
mImageIds[position] = android.R.drawable.btn_minus; // the desired image
mAdapter.notifyDataSetChanged();
}
이 사운드는 더 복잡합니다. 다른 사용자가 이미 말했던 것처럼 사용자 지정 어댑터를 작성하는 것이 원리를 이해하기를 바랍니다.
List 용 CustomAdapter를 사용하고 있습니까? 그렇다면 getView() 코드를 제공하십시오. 그렇지 않다면 구현하십시오. – user370305
당신은'ViewHolder'를 사용하고 있습니까? –
SimpleAdapter를 사용 중입니다. – Babloo