2

I pass data from another activity and use for args in querying in my database and I would like to query some data in my sqlite database and set it to edittext and textview. But it display nothing. When I check if there's some data been queried it return true. Please help

Here's the code in my first activity when clicking item on listview and passing data to another activity

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View
        view, int position, long id) {
        TextView temp = (TextView) view; 
        Intent i = new Intent(home.this, Update.class);
        Bundle bundle = new Bundle();
        bundle.putString("sulod", temp.getText().toString());
        Pig pig = new Pig();
        pig.pig_type = temp.getText().toString();
        i.putExtras(bundle);
        startActivity(i);
        finish();
    }
});

Code in my second activity

public void display(){
    Bundle bundle = getIntent().getExtras();
    String sulod = bundle.getString("sulod");
    Cursor c = myDb.filList();
    String sremarks = "";
    String saddress = "";
    int Id = 0;
    while (c.moveToNext()) {
        String name = c.getString(1);
        if(name == sulod){
            Id = c.getInt(0);
            sremarks = c.getString(2);
            saddress = c.getString(3);
        }
    }
    id.setText(Id+"");
    remarks.setText(sremarks);
    address.setText(saddress);
}

And in my dbhelper

public Cursor filList() {
    SQLiteDatabase db = this.getWritableDatabase();
    String[] columns = {COL_1, COL_2, COL_3, COL_4};
    return db.query(TABLE_NAME, columns, null, null, null,
    null, null);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Vince Ko
  • 21
  • 3
  • The problem is probably that `name == sulod` tests to see if they're the same object, not that their values are the same (you want `name.equals( sulod )` -- see [this answer](http://stackoverflow.com/a/513839/2096401). Also, would it not be better to pass `sulod` into the `filList()` function and have SQLite use it in a `WHERE` clause instead of filtering manually? – TripeHound Jan 04 '17 at 12:10

0 Answers0