-2

SQLiteクエリを実行しているDBConnector.Javaに変数を渡したいのですが、その方法がわからないため、サポートが必要です。

public void onItemSelected(AdapterView<?> parent, View view, int position,long id) 
    {
                spinnerRub.setSelection(position);      
            myRub = (String) spinnerRub.getSelectedItem();

    }

ここで、myRubをDBConnector.Javaに渡します。

public List<String> getAllCapabilities1()
{             

List<String> Caps = new ArrayList<String>();

                String selectQuery = "SELECT Cap_Name FROM capability where Rub_ID = 'myRub'";

            SQLiteDatabase database = this.dbOpenHelper.getReadableDatabase();
            //Cursor cursor = database.rawQuery(selectQuery, null);
            Cursor cursor = database.rawQuery(selectQuery, null);
            // looping through all rows and adding to list
            if (cursor.moveToFirst()) 
            {
                do 
                {
                  Caps.add(cursor.getString(0));
                } while (cursor.moveToNext());
            }

            // closing connection
            cursor.close();
            database.close();

            // returning lables
            return Caps;
        }   

しかし、私はそれをするのに苦労していて、助けが必要です。

4

5 に答える 5

4

インテントを使用してデータを渡します:

  i.putExtra("myRub",myRub);

オブジェクトはどこにiありますかIntent

を使用して他のアクティビティで取得する

Bundle extras = getIntent().getExtras();
String a = extras.getString("myRub");
于 2013-03-06T10:59:26.567 に答える
1

dbconnetion.java ファイルでこれを変更し、メソッドまたは sharedpref を介して myrub を渡します。

String selectQuery = "SELECT Cap_Name FROM capability where Rub_ID = '"+myRub+"'";

二つの活動の間

Intent i = new Intent(Intent.ACTION_VIEW);
i.putExtra("myrub", "This value one for ActivityTwo ");
startActivity(i);
于 2013-03-06T10:56:50.140 に答える
0

データをアクティビティに渡して取得するサンプルを次に示します。

Intent intent = new Intent();
intent.setClass(this, New.class);

Bundle b = new Bundle();
b.putInt("action", nResponse ); // integer value
b.putString("homename", sHomeName); // string value
intent.putExtras(b);
startActivity(intent);

new.class の oncreate メソッドに従ってください

Bundle b = getIntent().getExtras();
if( b != null ){
    nAction = b.getInt("action");
    sHomeName = b.getString("homename");
}
于 2013-03-06T11:08:14.390 に答える
0

あなたの活動で(あなたがdbConnectorへの参照を持っていると仮定していますか?):

spinnerRub.setSelection(position);      
myRub = (String) spinnerRub.getSelectedItem();
dbConnector.setMyRub(myRub);

DBConnector.java 内

public void setMyRub(String myRub){
    // do what you need to do with myRub
}
于 2013-03-06T11:27:57.870 に答える
-1

インテントを使用してアクティビティ間でデータを渡す

   Intent intent = new Intent(yourActivity.this, DBConnector.class);
   intent.putExtra("myRub", myRub);
   startActivity(intent);

getIntent().getExtras()そして、それを取り戻すために使用します

于 2013-03-06T11:02:08.483 に答える