开发者

Show two columns from SQLite as same string in a listview in android

Hi I am developing an android in which I am loading data from database and showing it in a List View. My code is as follows

public class rel extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.refill);
    //Creating an obj开发者_运维知识库ect called mydbhelper
    Dbms mydbhelper = new Dbms(this);
    //Loading the database in writable format
    SQLiteDatabase db=mydbhelper.getWritableDatabase();
    String[] id= new String[]{"_id","medicine","hs"};
    //Cursor
    Cursor c = db.query("medicines",id,null,null,null, null,null);
    startManagingCursor(c);
    String[] from = new String[]{"medicine"};
    int[] to = new int[] { R.id.textlist1};
     // Now creating an array adapter and set it to display using my row
    SimpleCursorAdapter notes =new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
    setListAdapter(notes);



}

What i want to achieve is show a list view as "Medicine-hs" in which medicine is from one column and hs is from an another column of database. For example as XYZ-HS1 ABC-HS2 as the listview contents

How to achieve this? Right now I am able to get only Medicine

Please give your kind suggestions

}


I want to say replace this:

    String[] from = new String[]{"medicine"};
    int[] to = new int[] { R.id.textlist1};

with this:

    String[] from = new String[]{"medicine", "medicine-hs"};
    int[] to = new int[] { R.id.textlist1, R.id.textlist2};

You will of course need to have a R.id.textlist2 available to use in your layout.

EDIT: Reverted back to the previous revision, which solved the problem.


What you could do is execute the rawQuery() method off the DBHelper class with SQL that combines the fields like so:

SELECT medicine + "-" + hs AS medicineHs FROM medicines ...

so the string array would be

String[] from = new String[]{"medicineHs"};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜