您好我有一個擴展名爲「KnowledgeBaseHelper」的SQLiteOpenHelper的類。 我一直使用它一段時間與我的類擴展活動,但後來我決定從使用ListActivity轉移到ListFragment,問題是,當我試圖實例化我的類名爲KnowledgeBaseHelper像這樣「KnowledgeBaseHelper helper = new KnowledgeBaseHelper (ListActivity.this);」它給我一個錯誤「構造函數KnowledgeBaseHelper(ListActivity)是不確定的」如何實例化ListFragment上的SQLiteOpenHelper類?
這通常工作時,我擴展ListActivity但現在我股票與此錯誤。實例化與ListActivity和FragmentActivity不同嗎?
感謝
下面是我的代碼
public class ListActivity extends ListFragment {
ArrayList<String> symptomList;
String name;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment_generalsymptoms, container,
false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
new LoadSymptoms().execute();
}
class LoadSymptoms extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
KnowledgeBaseHelper helper = new KnowledgeBaseHelper(
ListActivity.this);
return null;
}
}
對於SQLiteOpenHelper,我有一個很長的代碼和方法,所以我決定只包括很少。
public class KnowledgeBaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "docdroid";
//... I deleted the following lines
public KnowledgeBaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
// Create Clinic Table
createTable(db, TABLE_CLINIC, CLINIC_COLUMN);
//... I deleted the following lines
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CLINIC);
onCreate(db);
//... I deleted the following lines
}
}
是否有其他方法來實例化在碎片中擴展SQLiteOpenHelper的類?
謝謝@laalto!像魅力一樣工作。抱歉,我沒有足夠的代表投票答案。 – sander126
@ sander126然後接受這個答案。通過點擊刻度標記 –
我們走了。我需要等幾分鐘才能打勾。現在它開始了。非常感謝! – sander126