안드로이드와 자바를 처음 접했습니다. 그 값으로 목록보기 항목의 위치를 찾는 방법이 있는지 궁금 해서요.android ListView : 항목 값에서 항목 위치 가져 오기?
예 : "list 1108"이라는 문자열을 표시하는 항목이 내 listview에있는 경우 어떻게 "Product 1108"의 위치를 얻을 수 있습니까?
나는 그것이 의미가 있기를 바랍니다.
편집 :
private void updateListView() {
final ListView lvCheckList = (ListView) findViewById(R.id.lvCheckList);
Map<String, ?> keys = checkListData.getAll();
ArrayList<String> checkListStrings = new ArrayList<String>();
for (Map.Entry<String, ?> entry : keys.entrySet()) {
if (entry.getKey().equals(currentList + entry.getValue())) {
checkListStrings.add((String) entry.getValue());
}
if (entry.getKey().equals(currentList + entry.getValue() + "Checked")) {
//set Item to checked/unchecked
}
}
ArrayAdapter<String> checkListArrayAdapter = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_checked,
checkListStrings);
lvCheckList.setAdapter(checkListArrayAdapter);
}
이 코드는 된 SharedPreferences에 저장하여 항목을 가져오고있는 ListView에 표시합니다. 왜 그것이 작동하는지 나에게 묻지 마라. 단지 그렇게한다.
은 이제 선택 또는 선택 해제하려면 다음 중 하나를 목록 항목을 설정 여기에 일하려는하지만 목록보기가 아직 채워되지 않았기 때문에 그것이 가능하다고 생각하지 말아 어떤이 줄을if (entry.getKey().equals(currentList + entry.getValue() + "Checked")) {
//set Item to checked/unchecked
}
를 참조하십시오.
lvCheckList.setItemChecked (위치 :
는 그래서 ArrayAdapter와에 나는이 코드를 사용할 수 있도록 목록보기의 항목을 정렬하고 임 찾고 어떤 값 항목을 찾아 해당 항목의 위치를 얻을 필요 , 가치);
희망적으로 말이야.
가 어떻게 값을 받고 구현할 목록보기
onItemClickListener()
이을 할 수 있습니까? – tyczj
값은 SharedPreferences에서로드됩니다. –
왜 필요한가요? (나는 당신이 어디에 표시 값을 알고 있지만 어떤 위치에 동시에 가질 수 있는지 알 수 없다.) – njzk2