0

メイン.JAVA

public void onClick(View arg0) {
    switch (arg0.getId()) {
    case R.id.buttonupdate:
        String name = sqlName.getText().toString();
        String value = sqlValue.getText().toString();
        MainActivity entry = new MainActivity(Main.this);
        entry.open();
        entry.createEntry(name, value);
        entry.close();
        break;
    case R.id.buttonview:
        Intent intentone = new Intent();
        intentone.setClassName("com.example.sqltwo", "com.example.sqltwo.View");
        startActivity(intentone);
        break;
    case R.id.buttonsearch:
        String searchtext = sqlQuery_value.getText().toString();
        break;
    }   public void onClick(View arg0) {
    switch (arg0.getId()) {
    case R.id.buttonsearch:
        String name = sqlName.getText().toString();
        String value = sqlValue.getText().toString();
        MainActivity entry = new MainActivity(Main.this);
        entry.open();
        entry.createEntry(name, value);
        entry.close();
        break;
    case R.id.buttonview:
        Intent intentone = new Intent();
        intentone.setClassName("com.example.sqltwo", "com.example.sqltwo.View");
        startActivity(intentone);
        break;
    case R.id.buttonsearch:
        String searchtext = sqlQuery_value.getText().toString();
        break;
    }

MAINACTIVITY.JAVA

public long createEntry(String name, String value) {
    ContentValues cv = new ContentValues();
            cv.put(KEY_NAMES, name);
            cv.put(KEY_VALUES, value);
            return qdatabase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
    String[] columns = new String[]{KEY_NAMES, KEY_VALUES};
    Cursor c = qdatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    String result = "";

    int iValue = c.getColumnIndex(KEY_VALUES);
    int iName = c.getColumnIndex(KEY_NAMES);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
        result = result + c.getString(iName) + "\n" + c.getString(iValue) + "\n";
    }
    return result;  
}
public String search(String searchtext) {
    String searchresult = "";
    String arg = searchtext;

    String query = "select * from " + DATABASE_TABLE + " where title=\"" + arg +"\"";

    Cursor c = qdatabase.rawQuery(query, new String[] {arg});
    int iName = c.getColumnIndex(KEY_NAMES);

    if (c.moveToFirst()) {
        searchresult = searchresult + c.getString(iName);
    }

    return searchresult;

}

R.id.buttonsearch の場合:

TextEdit を取得し、searchtext に格納します。検索関数を実行して、そのクエリに一致するすべての行を返すには、MainActivity の検索テキストが必要です。Main の検索テキストを MainActivity にリンクするにはどうすればよいですか?

4

1 に答える 1

0

MAIN.JAVA では AsyncTask で AsyncTask を使用します メソッド doInBackground でデータベースに接続し (ソース MAINACTIVITY.JAVA を使用)、メソッド onPostExecute で MAIN.JAVA を変更します

例えば

private class loudAllTranslate extends
        AsyncTask<Void, Void, HashMap<String, Translate>> {

    Context context;
    String fullText;

    loudAllTranslate(Context cont, String fullText_) {
        context = cont;
        fullText = fullText_;
    }

    @Override
    protected void onPostExecute(HashMap<String, Translate> success) {
        super.onPostExecute(success);

        // do somting

    }

    @Override
    protected HashMap<String, Translate> doInBackground(Void... params) {

        LBD conection = new LBD(context);
        conection.open();
        conection.tblSettings();

        HashMap<String, Translate> listTranstate = Settings
                .updateAllTranslate(fullText);
        conection.close();
        return listTranstate;

    }

}
于 2013-03-04T14:40:24.433 に答える