2013-02-22 19 views
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編譯器工作不給我的錯誤,但它崩潰時,我按在列表中的位置0c.getstring不ListActivity發現

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(); 
} 

}

回答

0

你必須調用cursor.moveToFirst()cursor.moveToPosition(int),然後才能獲得列數據。