0
用好我用我現有的數據庫,我做了一個列表<>「mSorular」與此代碼:Android的數據庫中創建列表,如何在ListFragment
public class TestAdapter {
private final Context mContext;
private SQLiteDatabase mDb;
private DataBaseHelper mDbHelper;
public TestAdapter(Context context) {
this.mContext = context;
mDbHelper = new DataBaseHelper(mContext);
}
public List<soru> getTestData() {
List<soru> mSorular = new LinkedList<soru>();
try {
Cursor mCur = mDb.query("Soru", null, null,
null,
null,
null,
null,
null);
if (mCur != null) {
if (mCur.moveToFirst()) {
do {
soru Soru = new soru();
Soru.setmSoru(mCur.getString(2));
Soru.setmCevap1(mCur.getString(3));
Soru.setmCevap2(mCur.getString(4));
Soru.setmCevap3(mCur.getString(5));
mSorular.add(Soru);
} while (mCur.moveToNext());
}
}
return mSorular;
} catch (SQLException mSQLException) {
Log.e(TAG, "getTestData >>" + mSQLException.toString());
throw mSQLException;
}
}
之後,我想用我的mSorular名單一個listfragment。當我嘗試
public class framelist extends ListFragment {
private static String tag = "sqllist";
TestAdapter adapter = new TestAdapter(this);
它給出了這樣的錯誤:
The constructor TestAdapter(framelist) is undefined
沒有這個名單將返回空。所以我如何使用我的列表中的這個列表片段
智者的另一個版本是怎麼回事...好我可以問一個問題。之後,列表需要一些時間,我可以顯示一個加載屏幕,直到列表準備好? – mehmet
你當然可以。儘管如此,您應該將長時間運行的任務移至AsyncTask中。它會阻止UI線程,否則會讓你的應用感覺很慢。這裏是一個例子:http://stackoverflow.com/questions/19926157/android-progress-dialog-for-listview – SimonSays