开发者

compiling text for textview, including data from SQLite table

A stupid question that Im sure is really really simple - i开发者_JAVA技巧ve been trying to fiddle to solve it myself, but its all very new to me so any wisdom would be REALLY appreciated!

With an android application (using eclipse) if I want to compile text for a text view using some data that is stored in a sqlite database (I have a working dbhelper and table I want to use), what do I do? For example, I want a text box to say something like: "hello"+@user_name+"its been"+@days+"since your last visit!" where @user_name and @days are data in a table which I can currently retreive in a list (only 1 value in the list though). How do i compile a string to be shown in the text view (and assign this string to the view)?

Help!


String textViewValue="hello "+nameList.get(0)+" its been "+daysList.get(0)+" since youy last visit";

TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(textViewValue);


You said you have stored it in arryalist right? I am not sure if you have one ArrayList or two for Name and Days. (it would be good if you paste some of your code).

If your ArrayList is arrayList then you can get the name atleast like

"hello"+arrayList.get(0);     // will retrive first element

Or best way use cursor and fire a query which will store output of following in curser

 select Name,Days from your_table where Name='xyz';

then you can use folloing code to retrive data form curser (I am assuming there is only one row in cursor here)

if(cursor.moveToFirst()){  
String s = "hello"+cursor.getString(0)+"Its been"+cursor.getString(1)+"days since your last visit!!";
}

now set this s in your textbox.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜