sqlite没有读取数据或其他一些问题

时间:2012-04-27 19:30:38

标签: android sqlite

正如我在此处所说:android bundle wont carry over 这是更大代码的一部分:

 //1st activity
    public static String item = "";
    //inside the onClick method
    case R.id.bCreateCharacter:
    Intent iCreate = new Intent("silver.asw.charactersheet.CREATECHARACTER");
    startActivity(iCreate);
    //inside the onItemSelected method
    item = spin.getItemAtPosition(position).toString();

    //2nd Activity
    //database private info here
    public static String cName, cRace, cClass;
        public void viewChar(String[] item)
    {
        String[] columns = new String[] {KEY_NAME, KEY_RACE, KEY_CLASS};
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NAME + " = '" + item + "'", null, null, null, null);


        int name = c.getColumnIndex(KEY_NAME);
        int race = c.getColumnIndex(KEY_RACE);
        int clas = c.getColumnIndex(KEY_CLASS);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
        {
            cName = c.getString(name);
            cRace = c.getString(race);
            cClass = c.getString(clas);         
        }

    }

    //3rd activity

    //contains everything needed for database and other functions blah
    SecondActivity setup = new SecondActivity(this);
    //my work around for the bundle
    FirstActivity fa = new FirstActivity();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.character);
        TextView character = (TextView)findViewById(R.id.tvViewCharacter);

        String[] item = {fa.item};
        setup.open();
        setup.viewChar(item);
        setup.close();
        character.setText(setup.cName);

    }

以上链接仅仅是对此代码的疑难解答。我试图看看'项目'是否正在通过......而且显然不是......现在'项目'正在通过,但我还在拉空。数据库就在那里,因为选择字符的微调器填充了DB中的名称。如果它有帮助,我也在第二个活动中尝试了这个:

public String getName(String[] item) throws SQLException
{
    // TODO Auto-generated method stub
    String[] columns = new String[] { KEY_NAME, KEY_RACE, KEY_CLASS };
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NAME + " = '" + item + "'", null, null, null, null);
    if (c != null)
    {
        c.moveToFirst();
        String cName = c.getString(1);
        return cName;
    }
    return null;
}

并关闭一个力(当然,添加到第三个活动:String name = getName(item))

0 个答案:

没有答案