I have a cursor adapter to populate a listview based on queries, I want to control the layout of listview by passing a variable in the adapter I do the following
public class QueryCursorAdapter extends CursorAdapter{
View retView;
private DBHelper mHelper;
public QueryCursorAdapter(Context context, Cursor c,int QCase) {
super(context, c, QCase);
}
Shouldnt put the variable in as well in the bindview like
public void bindView(View view, Context context, Cursor cursor,int qcase)
Why it says I need to declare class as abstract?
Is there any other way to control the layout based on the type of my queries in sqlite?
Take a look at bindView method - it can take only 3 defined params.
When you say your class extends CursorAdapter
, you should implement this method, as it is declared as abstract
in CursorAdapter
.
So, you should put only these 3 params in your implementation of bindView
. When you put 4th param, system consider that it is not implementation of base method, but it's your own method.
That's why you get message about declaring class as abstract
, because you didn't implement base abstract method.
You can pass your needed param to constructor (as you do now) and save it to correspondent field of your class.
Then, in bindView
method you can just use this field as you need.
Upd. Moreover, you can use as many params as you need - just create your own constructor, for example, CursorAdapter(Context context, Cursor c, param1, param2 ... paramN)
and inside it don't forget to call base constructor CursorAdapter(Context context, Cursor c)
. Save your params into class fields and then use them in bindView
and other methods as you need.
Upd2. Code example:
public class QueryCursorAdapter extends CursorAdapter{
View retView;
private int myParam1, myParam2, myParam3;
private DBHelper mHelper;
public QueryCursorAdapter(Context context, Cursor c, int param1, int param2, int param3) {
super(context, c);
myParam1 = param1;
myParam2 = param2;
myParam3 = param3;
}
Then you can use these myParam1-2-3 anywhere in your adapter.