목록보기 나는 왜 그런 일이 일어나고 있는지 말할 수있는 첫 번째 가치를 반복적으로 얻고 있습니다. 아래는 기본 어댑터가 아래 목록보기 용 어댑터 코드는하지만 가져 오는 경우에만 첫 번째 값이 반복적으로 어디 내가 잘못 가고listview with baseadapter android
private void dbGet(String profileType) {
String[] projection = { "filename", "path", "created_on" };
String selection = "profile_type=?";
String[] selectionArgs = { profileType };
Cursor c = sqldb.query(DatabaseHandler.file_list_table_name, projection,
selection, selectionArgs, null, null, "id DESC");
if (c != null && c.getCount() != 0) {
DownloadedFileListAdapter downloadedFileListAdapter = new DownloadedFileListAdapter(
this, c);
listView.setAdapter(downloadedFileListAdapter);
}
}
라고 호출하는 기능입니다. 당신이 사용하는
public class DownloadedFileListAdapter extends BaseAdapter {
Context mContext;
Cursor mCursor;
boolean movetonext = false;
private LayoutInflater inflater;
DownloadedFileListAdapter(Context m, Cursor c) {
mContext = m;
mCursor = c;
Log.d("checking :", "in DownloadedFileListAdapter activity");
}
@Override
public int getCount() {
return mCursor.getCount();
}
@Override
public Object getItem(int position) {
return mCursor.moveToNext();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.display_file_list, null);
TextView fileName = (TextView) convertView.findViewById(R.id.downloaded_file_name);
TextView fileCreatedOn = (TextView) convertView.findViewById(R.id.file_path_created_on);
if(mCursor != null && mCursor.moveToFirst()){
fileName.setText("" + mCursor.getString(0));
fileCreatedOn.setText("" + mCursor.getString(2));
mCursor.moveToNext();
}
getItem(position);
return convertView;
}
}
어댑터에서 커서를 사용하지 마십시오. 먼저 커서를 반복하고 내용이있는 객체 목록을 채 웁니다. 그런 다음 어댑터로 보내십시오. –
감사합니다. 함께 사례를 공유해주세요. – user3721186
http://stackoverflow.com/questions/9009480/convert-results-of-sqllite-cursor-to-my-object 및 http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view –