-1

在这个链接中是我如何将数据插入到我的数据库中,所以现在我想知道如何制作一个按钮,将 textview 值编辑为我的数据库列的值。

4

1 回答 1

0

好的,这是帮助您处理数据库和 Listactivity 的代码

public class MyDB { 
    protected static final String TAG = "TAG";

    private final Context mContext;
    private SQLiteDatabase mDb;
    private MyDBhelper mDbHelper;
public MyDB(Context context){   
    this.mContext = context;
    mDbHelper = new MyDBhelper(mContext);
}

public MyDB createDatabase() throws SQLException 
{
    try 
    {
        mDbHelper.createDataBase();
    } 
    catch (IOException mIOException) 
    {
        Log.e(TAG, mIOException.toString() + "  UnableToCreateDatabase");
        throw new Error("UnableToCreateDatabase");
    }
    return this;
}

public MyDB open() throws SQLException 
{
    try 
    {
        mDbHelper.openDataBase();
        mDbHelper.close();
        mDb = mDbHelper.getReadableDatabase();
    } 
    catch (SQLException mSQLException) 
    {
        Log.e(TAG, mSQLException.toString());
        throw mSQLException;
    }
    return this;
}


    public Cursor getplaces() 
    {
        Cursor c = mDb.query(Constants.DATABASE_NAME, null, null, null, null, null, null);
        return c;

    }

    public void close() 
    {
        mDbHelper.close();
    }

}

和活动显示列表

public ListplaceActivity extends ListActivity {



    private static MyDB mDbHelper;
    String[] from = new String[] { Constants.TITLE_NAME };
    int[] to = new int[] {R.id.place_title};


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        mDbHelper = new MyDB(this);
        mDBHelper.open();
        Cursor c = mDbHelper.getplaces();
        setListAdapter(new SimpleCursorAdapter(this, 
                  android.R.layout.simple_list_item_1, c, 
                  from, to));

}
于 2012-09-05T20:22:29.050 回答