Reputation: 635
In my applicatio i have 1 listview,filling data from database using arrayadapter.
Here is following code:
public void onClick(View v) {
// TODO Auto-generated method stub
Cursor c = db.gethouseholdTitle();
startManagingCursor(c);
// if(cat.equals("Income"))
// {
//// System.out.println("inside if="+select);
//// Cursor cin = db.income();
String[] fromdes = new String[] {db.KEY_DATE,db.KEY_DESC,db.KEY_INCOME,db.KEY_TOTAL};
int[] todes = new int[] {R.id.text1 ,R.id.text3,R.id.text5,R.id.text7};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.columnview, c, fromdes, todes);
// System.out.println("notes="+notes.getCount());
// setListAdapter(notes);
lv.setAdapter(notes);
}
But showing error:
The constructor SimpleCursorAdapter(new View.OnClickListener(){}, int, Cursor, String[], int[]) is undefined
What i am doing wrong.Thanks in advance.I think we cant able to fill cursor adapter inside a click function??
Upvotes: 1
Views: 331
Reputation: 57316
Change this line:
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.columnview, c, fromdes, todes);
into this:
SimpleCursorAdapter notes = new SimpleCursorAdapter(MyActvity.this, R.layout.columnview, c, fromdes, todes);
Here MyActivity
should be the actual name of your activity.
At the same time, I'll draw your attention to the following excerpt from SimpleCursorAdapter
javadoc:
This constructor is deprecated. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.
Upvotes: 4