이 코드를 사용하여 커서에서 항목을 가져 오지만 목록에 하나의 항목 만 반환합니다. 그래서, 어떻게 내 목록에있는 모든 항목을 가져올 수 있습니까? 이것이 내 코드입니까?안드로이드에서 커서의 모든 항목 가져 오기
class MyAdapter extends SimpleCursorAdapter
{
private Context context;
public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
{
super(context, layout, c, from, to);
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent){
Cursor cursor = getCursor();
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View v = inflater.inflate(R.layout.sbooks_row, null);
TextView title = (TextView)findViewById(R.id.title);
if(title != null){
int index = cursor.getColumnIndex(SBooksDbAdapter.KEY_TITLE);
String type = cursor.getString(index);
title.setText(type);
}
TextView lyrics = (TextView)findViewById(R.id.lyrics);
if(lyrics != null){
int index = cursor.getColumnIndex(SBooksDbAdapter.KEY_LYRICS);
String type = cursor.getString(index);
lyrics.setText(type);
}
ImageView im = (ImageView)findViewById(R.id.icon);
if(im!=null){
int index = cursor.getColumnIndex(SBooksDbAdapter.KEY_FAVORITE);
int type = cursor.getInt(index);
if(type==1){
im.setImageResource(android.R.drawable.btn_star_big_on);
}
else{
im.setImageResource(android.R.drawable.btn_star_big_off);
}
}
return v;
}
안녕하세요, 귀하의 조언과 함께 내 코드를 수정하려고합니다. newView(), bindView() 함수를 사용하고 모든 항목을 반환합니다. 하지만 여전히 Listview에 문제가 있습니다. 정상적으로 표시되지 않습니다. 나는 이것이 스크롤 바를 위아래로 끌 때 다르게 표시합니다. 뭔가 잊을 수 있니? – Dennie
항목이 정상적으로 표시되지 않는다는 것은 무엇을 의미합니까? 오래된 항목이 표시되면 새 항목 대신 (정상적인 어댑터로 인해 발생하는) 대신 재활용 로직 (bindView())에 문제점이 있어야합니다. 여기에 설명 된대로 ViewHolder 패턴을 사용하는 것이 좋습니다. http://www.youtube.com/watch?v=N6YdwzAvwOA at 0:09:02 –
해당 비디오 링크는 ListView 아래에서 무슨 일이 벌어지고 있는지 이해하고자하는 모든 사용자에게 매우 유용합니다. 감사 드미 타르! –