채우려는 목록보기가있는 활동을 실행할 때 비어있는 것으로 표시됩니다. 그러나 logcat에서 사용자 지정 CursorAdapter가 내 데이터를 통해 실행되고 적어도 일부보기를 반환하는 것을 볼 수 있습니다.ListView를 채우지 않은 사용자 지정 CursorAdapter
public class JobAdapter extends CursorAdapter {
private String status;
private static final String tag ="TESTING CursorAdapter";
public JobAdapter(Context context, Cursor cur, boolean autoRequery, String s) {
super(context, cur, autoRequery);
Log.d(tag, "Job adapter create");
status = s;
}
@Override
public void bindView(View row, Context context, Cursor cursor) {
Log.d(tag, "Starting a bind");
Cursor c = getCursor();
if(!c.isClosed()){
TextView companyName = (TextView) row.findViewById(R.id.listCompanyName);
TextView positionTitle = (TextView) row.findViewById(R.id.listPositionTitle);
while(!c.isLast() && !c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
Log.d(tag, "bind - moving c to next 1");
c.moveToNext();
}
if(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
Log.d(tag, "found a status and trying to populate the view");
companyName.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_COMPANY)));
positionTitle.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_POSITION)));
Log.d(tag, "Company name = "+c.getString(c.getColumnIndex(JobsDbAdapter.KEY_COMPANY)));
if(c.isLast()) {
Log.d(tag, "bind - Closing c 1");
c.close();
}else {
Log.d(tag, "bind - moving c to next 2");
c.moveToNext();
}
}
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Cursor c = getCursor();
Log.d(tag, "Starting a new");
final LayoutInflater inflater = LayoutInflater.from(context);
View row = inflater.inflate(R.layout.job_list_item, parent, false);
if(!c.isClosed()){
TextView companyName = (TextView) row.findViewById(R.id.listCompanyName);
TextView positionTitle = (TextView) row.findViewById(R.id.listPositionTitle);
while(!c.isLast() && !c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
Log.d(tag, "new - moving c to next 1");
c.moveToNext();
}
if(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
Log.d(tag, "new - found a status and trying to populate the view");
companyName.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_COMPANY)));
positionTitle.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_POSITION)));
if(c.isLast()) {
Log.d(tag, "new - Closing c 1");
c.close();
}else {
Log.d(tag, "new - moving c to next 2");
c.moveToNext();
}
}
Log.d(tag, "new - returning row");
return row;
}
}
나는 커서가 데이터베이스의 끝에 도달 있는지 확인해야 하는가? 아니면 나를 위해 처리 될 것인가? 이 어댑터를 사용내 클래스는 단순히
public class AppliedForActivity extends ListActivity {
private JobsDbAdapter mDbHelper;
public void onCreate(Bundle savedInstanceState) {
Log.d("TESTING C", "STARTING THE APPLIED FOR ACTIVITY");
super.onCreate(savedInstanceState);
setContentView(R.layout.job_list);
mDbHelper = new JobsDbAdapter(this);
mDbHelper.open();
Cursor c = mDbHelper.fetchAllJobs();
setListAdapter(new JobAdapter(this, c, false, "applied for"));
}
}
는 중괄호를 용서하십시오, 내가 잘못 복사 한 수 있습니다.