well I am using my existing database, I made a list<> "mSorular" with this code:
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;
}
}
after that I want to use my mSorular list in a listfragment. When I try to
public class framelist extends ListFragment {
private static String tag = "sqllist";
TestAdapter adapter = new TestAdapter(this);
it gives this error:
The constructor TestAdapter(framelist) is undefined
without this my list will return empty. so how can I Use my list in this listfragment
ListFragment
is not a Context
. First change it to use the attached Activity
as Context
, and then move it into the onCreate()
method of the Fragment because before this call there might not be an Activity
attached. (actually it's after the onAttach(Activity)
call)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate();
TestAdapter adapter = new TestAdapter(getActivity());
...
{