我的列表视图有问题。当我将我的 SQL 查询传递给 ListView 时,列表视图会在每一行中显示
* com.MyPackageName.MyAppName.MyClassName@Some Number (like 2c62a7d0) *
我不知道为什么这是我返回所有内容的函数
public List<AddedZekrView> getAllRecordList(){
ArrayList<AddedZekrView> addedZekrFields = new ArrayList<AddedZekrView>();
//Cursor cursor= database.query(ZekrdbOpenHelper.TABLE_ZEKR, allColumns, null, null, null, null, null);
Cursor cursor= database.query(ZekrdbOpenHelper.TABLE_ZEKR, allColumns, null, null, null, null, null);
if (cursor.getCount()>0) {
cursor.moveToFirst();
while (cursor.moveToNext()) {
Log.i("In while", cursor.getPosition()+"");
AddedZekrView addedZekrFieldNew=new AddedZekrView();
// you have to declare all fields such as **COLUMN_ID** in your addedZekrView activity
addedZekrFieldNew.ID=cursor.getLong(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_ID));
addedZekrFieldNew.TITLE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_TITLE));
addedZekrFieldNew.DESC=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_DESC));
addedZekrFieldNew.MAX_COUNT=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_MAX_COUNT));
addedZekrFieldNew.CREATE_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_CREATE_DATE));
addedZekrFieldNew.LAST_COUNT_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_LAST_COUNT_DATE));
addedZekrFieldNew.MODIFY_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_MODIFY_DATE));
addedZekrFieldNew.EXPIRATION_DATE=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_EXPIRATION_DATE));
addedZekrFieldNew.START_AZ=cursor.getString(cursor.getColumnIndex(ZekrdbOpenHelper.COLUMN_START_AZ));
Log.i("return cursor", addedZekrFieldNew.TITLE+ " " +addedZekrFieldNew.DESC);
addedZekrFields.add(addedZekrFieldNew);
}
}
//return List Object
return addedZekrFields;
}
这是我的java文件:
public class AddedZekrView extends ListActivity {
public Long ID;
public String TITLE;
public String DESC;
public String MAX_COUNT;
public String CREATE_DATE;
public String CURENT_COUNT;
public String LAST_COUNT_DATE;
public String MODIFY_DATE;
public String EXPIRATION_DATE;
public String START_AZ;
ZekrDataSource datasource;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//PreferenceActivity is a subclass of ListActivity (source), so you can either remove the setContentView() method call or add a subview with id android.R.list in added_zekr_view.xml
//I removed setContentView(R.layout.added_zekr_view);
//setContentView(R.layout.added_zekr_view);
datasource=new ZekrDataSource(this);
datasource.open();
List<AddedZekrView> addedZekrFields2 = datasource.getAllRecordList();
// if this is first time that we run App so maybe we dont have any data on it so we need to check that
//And call our list View again
if (addedZekrFields2.size()==0) {
Toast toast = Toast.makeText(this, "Nothing Founded.",Toast.LENGTH_LONG);
toast.show();
//datasource.insertRecord(null, null, null, null, null, null);
addedZekrFields2 = datasource.getAllRecordList();
}
ArrayAdapter<AddedZekrView> adapter = new ArrayAdapter<AddedZekrView>(this, android.R.layout.simple_expandable_list_item_1, addedZekrFields2 );
setListAdapter(adapter);
}
}
有人可以帮我弄清楚吗。太感谢了。