在ListActivity中找不到c.getstring

时间:2013-02-22 15:25:44

标签: android getstring

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

    }

大家好我想问为什么它在getsList中没有工作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();
}

}

1 个答案:

答案 0 :(得分:0)

您必须先致电cursor.moveToFirst()cursor.moveToPosition(int),然后才能获取列数据。