在选定的方法数组适配器上

时间:2015-11-03 18:15:32

标签: android adapter

我为onItemSelected尝试Spinner方法尝试更改TextView,这取决于Spinner的输入。问题是我遇到了第一个输入,一旦我选择了不同的输入,它就不会改变。

以下是MainActivity中的方法和onselect方法

public void listView(int index){

    int indexs=0;
    Cursor res= db.getMainData();
    if(res.moveToFirst()){
        PPLNAMERES.setText(res.getString(indexs));
    } else{
        Toast.makeText(MainActivity.this,"No Data",Toast.LENGTH_LONG).show();
        return;
    }
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    PPLNAMERES = (TextView)findViewById(R.id.PPLNAMEGETNAME);
    listView(position);
}

sqliteopenhelper类中的getMainData方法

   public Cursor getMainData() {
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor result = db.rawQuery("select NAMEPPL from " + Table_name2, null);
    return result;

     }

1 个答案:

答案 0 :(得分:0)

错误消息显示

Failed to read row 0, column 1 from a CursorWindow 所以你的查询返回0行。你的if语句应为:

if(cur!=null){
    // Best to manage any non-null cursor as then it will be closed when the
    // activity is stopped
    startManagingCursor(cur);
    // Only if a row was found
    if(cur.moveToFirst()) {
        Log.d("debug Cursor" , "can be created");
        Log.d("KEY_PHOTO_HKID_HEX" , cur.getString(1));
        Log.d("KEY_PHOTO_ADDRESS_HEX" , cur.getString(2));
        Log.d("KEY_PHOTO_BANK_HEX" , cur.getString(3));
    }else{
        // Handle no rows returned
    }
}else{
    Log.d("debug Cursor" , "cannot be created");
}