0
public class SimpleCursorAdapterConLogoActivity extends ListActivity
{

    private DatabaseHelper databaseHelper;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        databaseHelper = new DatabaseHelper(this);
        Cursor c = databaseHelper.getAllSiti();
        startManagingCursor(c);
        System.out.println("SimpleProvinceSimpleCursorAdapter con logo");
        setListAdapter(new ProvinceSimpleCursorAdapter(this, c));

    }

こんにちは皆さん、getstring onListItemClick でなぜ機能しないのかを知りたかったのですが、コンパイラはエラーを表示しませんが、リストの位置 0 を押すとクラッシュします

 protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

        final int index = position;
        databaseHelper = new DatabaseHelper(this);
        Cursor c = databaseHelper.getAllSiti();
        startManagingCursor(c);

        //You can add whatever you want to happen when you click here

        Log.i("testy", "I Clicked on Row " + index + " and it worked!");
        switch (index){
            case  0:
                {
                    Cursor c1 = databaseHelper.getAllSiti();
                    startManagingCursor(c1);
                    String nomeRegione = c.getString(c.getColumnIndex(SitiTable.NOME));
                    System.out.println(nomeRegione);

                        //System.out.println(nomeRegione);
                }
                break;
            case  1:
                System.out.println("hello2");
                break;
            case  2:
                System.out.println("hello£");   
                break;
        }           
  }
@Override
protected void onDestroy()
{
    super.onDestroy();
    databaseHelper.close();
}

}

4

1 に答える 1

0

列データを取得する前にcursor.moveToFirst()orを呼び出す必要があります。cursor.moveToPosition(int)

于 2013-02-22T15:30:21.293 に答える