私は2つの列(_id、name)のテーブル(カテゴリ)を持っています。最初の列のスピナーをテーブルに挿入します
私はカラム名を示すスピナーを持っています。
今、私は列を挿入する必要があります: "_id"別のテーブルに...しかし、私はそれを行う方法がわかりません。
提案がありますか?
私は私が使用しているコードを貼り付けます。
public Cursor recuperaCategoria()
{
final UsuariosSQLiteHelper usdbh =new UsuariosSQLiteHelper(this, "DBLlistaCompra", null, 1);
final SQLiteDatabase db = usdbh.getWritableDatabase();
String tableName = "Categorias";
String[] columns = {"_id","Nombre"};
return db.query(tableName, columns, null, null, null, null, null);
}
public void recCatSpinner() {
final Spinner addCatSpinner = (Spinner) findViewById(R.id.spIdCategoria);
catCursor = recuperaCategoria();
catCursor.moveToPosition(1);
catAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
addCatSpinner.setAdapter(catAdapter);
if (catCursor.moveToFirst()) {
do {
catAdapter.add(catCursor.getString(1));
Valor = catCursor.getString(1);
Log.v("valor Add Cat 100", Valor);
}
while (catCursor.moveToNext());
int id = catCursor.getInt(0);
String name = catCursor.getString(1);
Log.v("Dentro cursor","1");
if (db != null) {
Toast.makeText(getBaseContext(),catCursor.getString(0),Toast.LENGTH_SHORT).show();
db.close();
}
}
startManagingCursor(catCursor);
//catCursor.close();
addCatSpinner.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent,
View view2, int pos, long id) {
//recID();
valor = parent.getItemAtPosition(pos).toString();
Log.v("valor Add Cat", valor);
}
public void onNothingSelected(AdapterView<?> parent) {
// view.setText("nada");
}
});
catCursor.close();
}
私は(それがコラム「ノンブル」と表示されます)をスピナーから1つの項目を選択すると、私は1つの変数に保存することを希望カーソル "_id"の最初の列。コレクションに
別のテーブルにそれらを挿入するためにスクリプトを書きます別のテーブル。またはあなたの質問を絞り込む。 – Maxim
ありがとう、それはsqlliteです。私はスピナーで選択された名前で新しいカーソルを書いています。 – user1107620