1

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??

4

1 に答える 1

4

この行を変更します。

SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.columnview, c, fromdes, todes);

これに:

SimpleCursorAdapter notes = new SimpleCursorAdapter(MyActvity.this, R.layout.columnview, c, fromdes, todes);

ここMyActivityには、アクティビティの実際の名前が表示されます。

同時に、SimpleCursorAdapterjavadocからの次の抜粋に注目してください。

このコンストラクターは非推奨です。このオプションは、アプリケーションの UI スレッドでカーソル クエリが実行されるため、応答が遅くなったり、アプリケーションが応答しないというエラーが発生したりする可能性があるため、お勧めできません。別の方法として、LoaderManager を CursorLoader とともに使用します。

于 2012-07-16T13:41:06.127 に答える