Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将第一列微调器插入表中_Android - Fatal编程技术网

Android 将第一列微调器插入表中

Android 将第一列微调器插入表中,android,Android,我有一个包含两列(_id,name)的表(Categories) 我有一个显示列名的微调器 现在,我需要在另一个表中插入列:“\u id”…但我不知道如何做 有什么建议吗 我粘贴我正在使用的代码: public Cursor recuperaCategoria() { final UsuariosSQLiteHelper usdbh =new UsuariosSQLiteHelper(this, "DBLlistaCompra", null, 1); final SQL

我有一个包含两列(_id,name)的表(Categories)

我有一个显示列名的微调器

现在,我需要在另一个表中插入列:“\u 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();
}
categoria()的公共游标
{
最终usuariossqliteheloper usdbh=新的usuariossqliteheloper(这个“DBLlistaCompra”,null,1);
最终SQLiteDatabase db=usdbh.getWritableDatabase();
字符串tableName=“Categorias”;
字符串[]列={u id”,“Nombre”};
返回db.query(tableName,columns,null,null,null,null,null);
}
public void recCatSpinner(){
最终微调器addCatSpinner=(微调器)findViewById(R.id.spIdCategoria);
catCursor=RecurperaCategoria();
catCursor.moveToPosition(1);
catAdapter=newarrayadapter(这是android.R.layout.simple\u微调器\u项);
addCatSpinner.setAdapter(catAdapter);
if(catCursor.moveToFirst()){
做{
add(catCursor.getString(1));
Valor=catCursor.getString(1);
日志v(“valor添加100类”,valor);
} 
while(catCursor.moveToNext());
int id=catCursor.getInt(0);
String name=catCursor.getString(1);
Log.v(“Dentro游标”、“1”);
如果(db!=null){
Toast.makeText(getBaseContext(),catCursor.getString(0),Toast.LENGTH_SHORT.show();
db.close();
} 
} 
开始管理光标(catCursor);
//catCursor.close();
addCatSpinner.setOnItemSelectedListener(
新建AdapterView.OnItemSelectedListener(){
已选择公共无效项(AdapterView父项,
视图2,内部位置,长id){
//recID();
valor=parent.getItemAtPosition(pos.toString();
Log.v(“valor添加Cat”,valor);
}
未选择公共无效(AdapterView父级){
//view.setText(“nada”);
}
});
catCursor.close();
}

我希望当我从spinner中选择一个项目(它显示列“Nombre”)时,我将游标“\u id”中的第一列保存到一个变量中。

读取集合中的值,然后编写脚本将它们插入到另一个表中

SQLiteDatabase db = getReadableDatabase();
String[] columns = { _id };
String selection = "column_name" + "=?";
String orderBy = "_id ASC";
String[] selectionArgs = new String[] { "something" };
String groupBy = null;
String having = null;

Cursor cursor = db.query("table_name", "columns", selection, selectionArgs, groupBy, having, orderBy);

while(cursor.moveToNext()) {

   int id = cursor.getInt(0);
   String name = cursor.getString(1);

   // Add values to a collection
}
if(db.isOpen()) db.close();


如果您指的是SQLite db表,那么请编写一个sql脚本,该脚本将读取ID并将它们添加到另一个表中。或者缩小你的问题范围。谢谢,这是sqllite。我正在用在微调器上选择的名称编写一个新光标。
SQLiteDatabase db = getWritableDatabase();

for(int id : idCollection) {

  ContentValues values = new ContentValues();
  values.put("_id",   id);

  try {

    int id = db.insertOrThrow(TABLE_NAME, null, values);
  }
  catch (SQLException sqlEx) {

    // do something with exception
  } 
}

if(db.isOpen()) db.close();