Выборка столбцов строки в редактируемые тексты, идентификатор строки в текстовом представлении - PullRequest
0 голосов
/ 09 декабря 2011

У меня есть страница с числом редактируемых текстов, я хочу заполнить их столбцами необработанного текста с идентификатором строки, равным значению textview ... это то, что у меня есть на странице редактирования текста.

public class CBCreate extends Activity   {

EditText EditRecipe,EditRecipe2,EditRecipe3;
Button Rname;
CBDataBaseHelper entry;
TextView RowIDText;
Cursor c;
String name;
String category;
String description;
//final String SQL_STATEMENT = "SELECT Recipe_Name, Recipe_Category, Recipe_Description FROM RecipeData WHERE _id = " + RowIDText ;


public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.create); // sets the content view to main

    EditRecipe = (EditText) findViewById(R.id.editText1);
    EditRecipe2 = (EditText) findViewById(R.id.editText2);
    EditRecipe3 = (EditText) findViewById(R.id.editText3);
    RowIDText = (TextView) findViewById(R.id.RowID);
    Rname = (Button) findViewById(R.id.RecipeName);
    String RowID;
try{
    Bundle extras = getIntent().getExtras(); 

    if (extras != null) {
        RowID = extras.getString("SELECTED");
        RowIDText.setText(RowID);
    }

    if (RowIDText != null){
        entry = new CBDataBaseHelper(this);
        String s = RowIDText.getText().toString();
        int ID = Integer.parseInt(s);
        entry.open();
        Cursor cursor = entry.fetchRow(ID);

        if (cursor.moveToFirst()){ // data?
           name = cursor.getString(cursor.getColumnIndex(CBDataBaseHelper.KEY_NAME));
    }
        entry.close();
        EditRecipe.setText(name);
        EditRecipe2.setText(category);
        EditRecipe3.setText(description);

    }
    }catch (Exception e){
        String error = e.toString();
        Dialog d = new Dialog(this);
        d.setTitle("darn");
        TextView tv = new TextView(this);
        tv.setText(name);
        d.setContentView(tv);
        d.show();
    }
}

public void doIt(View view) {

            String Name = EditRecipe.getText().toString();
            String description = EditRecipe.getText().toString();
            String category = EditRecipe.getText().toString();
            entry = new CBDataBaseHelper(CBCreate.this);
            entry.open();
            entry.createEntry(Name, description, category);
            entry.close();
            EditRecipe.setText("");
            EditRecipe2.setText("");
            EditRecipe3.setText("");

}

public void goBack(View view){

    Intent myIntent = new Intent(this, CBFilter.class);
    startActivity(myIntent);


}

}

и тогда это то, что у меня есть в классе помощника базы данных ... я думаю, что я хочу вызвать этот метод?

    public Cursor fetchRow(long rowId) throws SQLException {
    Cursor mCursor = mydatabase.query(true, DATABASE_TABLE, new String[] { KEY_ROWID,
            KEY_CATEGORY, KEY_DESCRIPTION }, KEY_ROWID + "="
            + rowId, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;

}

1 Ответ

0 голосов
/ 09 декабря 2011

Я бы использовал mydatabase.rawquery (QUERY) вместо метода запроса курсоров.Думаю, разработчикам SQL проще.В любом случае, когда у вас есть значения в курсоре, вы можете сделать это

EditRecipe.setText(cursor.getString(0));
EditRecipe2.setText(cursor.getString(1));

Где 0 представляет первый столбец в вашей возвращенной таблице.Вы должны поместить этот код после вашего mCursor.moveToFirst ();

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...