조각에 3 개의 ListView가 있으며 이제는 새 페이지를 열고 일부 요소를 표시하기 위해 클릭 한 개체를 가져와야합니다.ListView에서 요소 가져 오기
문제점은 내 탭에서 ListView가 Sqlite db를 쿼리하여 채워지고 목록에 요소를 추가 할 때 모든 페이지가 0에서 시작된다는 것입니다. 그러나 내 DB에는 각 요소마다 다른 ID가 있습니다.
올바른 요소를 얻으려면 어떻게해야합니까?
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Integer pageToShow = getArguments().getInt(ARG_SECTION_NUMBER);
View rootView = inflater.inflate(R.layout.fragment_choose_character, container, false);
ListView listView = (ListView) rootView.findViewById(R.id.listViewPersonaggi);
personaggiDB = new DatabasePersonaggiHandler(getContext());
ArrayList<Personaggio> personaggi = personaggiDB.getAllPersonaggi(pageToShow);
// Adatto il personaggio alla grafica della lista
this.m_adapter = new PersonaggioAdapter(getContext(), R.layout.riga_personaggio, personaggi);
listView.setAdapter(this.m_adapter);
// Su ogni elemento della lista aggiungo il click
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent singoloPersonaggioIntent = new Intent(getContext(), SingoloPersonaggioActivity.class);
singoloPersonaggioIntent.putExtra("idPersonaggio", i);
startActivity(singoloPersonaggioIntent);
}
});
return rootView;
}
당신은 내가이 줄을 사용 볼 수 있듯이 :
ArrayList<Personaggio> personaggi = personaggiDB.getAllPersonaggi(pageToShow);
각 페이지가 다른 문자가 그래서 내 DB에서 얻을 문자의 유형을 이해합니다.
예를 들어 내 두 번째 탭 pageToShow = 2
의 첫 번째 요소에는 위치 0이 있지만 내 DB에는 id = 12
등이 있습니다.
아이디어가 있으십니까?
이 정보는 도움이 될 수 있습니다. https://stackoverflow.com/questions/3041218/assigning-id-to-a-row-in-an-android-listview – lib4