为textview编译文本,包括来自SQLite表的数据
我确信这是一个愚蠢的问题,真的很简单 - 我一直在尝试自己解决它,但这对我来说都是新的,所以任何智慧都会非常感激!
对于 Android 应用程序(使用 Eclipse),如果我想使用存储在 sqlite 数据库中的一些数据(我有一个工作的 dbhelper 和我想使用的表)来编译文本视图的文本,我该怎么办? 例如,我想要一个文本框显示如下内容: “你好”+@用户名+“自您上次访问以来已经”+@days+“了!” 其中 @user_name 和 @days 是表中的数据,我当前可以在列表中检索这些数据(尽管列表中只有 1 个值)。 如何编译要在文本视图中显示的字符串(并将该字符串分配给视图)?
帮助!
A stupid question that Im sure is really really simple - ive 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
String textViewValue="hello "+nameList.get(0)+" 自您上次访问以来已是 "+daysList.get(0)+";
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(textViewValue);
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);
您说您已将其存储在 arryalist 中,对吗?
我不确定您是否有一个或两个用于名称和日期的 ArrayList。 (如果你粘贴一些代码就好了)。
如果您的 ArrayList 是 arrayList 那么您至少可以获得名称
,或者最好的方法是使用游标并触发一个查询,该查询将在curser中存储以下输出
,然后您可以使用以下代码从curser中检索数据(我假设只有一行在光标处)
现在将其设置在文本框中。
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
Or best way use cursor and fire a query which will store output of following in curser
then you can use folloing code to retrive data form curser (I am assuming there is only one row in cursor here)
now set this s in your textbox.