需要帮助以列表形式显示带有图像的消息文本
我需要启动一个包含文本和图像列表的应用程序。我需要在带有图像的列表中显示这些文本消息。我使用线性布局用图像显示这些消息,如下所示。
for(int i=0;i<messages.size();i++)
{
FrameLayout f1= new FrameLayout(this);
LinearLayout l1 = new LinearLayout(this);
LinearLayout l2 = new LinearLayout(this);
im =new ImageView(this);
TextView tv =new TextView(this);
tv.setText(messages.get(i).getmessage());
im.setImageResource(R.drawable.person);
l1.addView(tv);
l2.addView(im);
f1.addView(l1);
f1.addView(l2);
((LinearLayout)findViewById(R.id.LinearlayoutMessage)).addView(f1);
}
一段时间后,我只需要刷新图像视图中的图像。我试图通过为每个图像视图设置 id 来做到这一点,但我只得到最后一个图像视图 id。
我知道有listview,但是它适合我的要求吗?我不知道我该如何完成我的任务。有人可以帮我吗?
I need to start an application that contains a list of text with images. I need to display these text messages in a list with images. I am displaying these messages with images by using linear layouts as shown below.
for(int i=0;i<messages.size();i++)
{
FrameLayout f1= new FrameLayout(this);
LinearLayout l1 = new LinearLayout(this);
LinearLayout l2 = new LinearLayout(this);
im =new ImageView(this);
TextView tv =new TextView(this);
tv.setText(messages.get(i).getmessage());
im.setImageResource(R.drawable.person);
l1.addView(tv);
l2.addView(im);
f1.addView(l1);
f1.addView(l2);
((LinearLayout)findViewById(R.id.LinearlayoutMessage)).addView(f1);
}
After some time I need to refresh only images in the image view. I am trying to do this by setting id's to each image view's but I get only last image view id.
I know there is listview, but is it suitable for my requirement? I don't know how can I do my task. Can anyone please help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的建议是使用适配器来显示图像和相应的文本。它将帮助您选择/聚焦项目。
请分享结果。
My suggestion would be to use Adapter for showing image and respective text. It will help you get selected/focused item.
Please share result.
我做了类似的事情..我只是做了一个 TextViews 列表(每行两个 TextView),我需要更新列表中的一个 TextView ..我所做的是一个垂直 LinearLayout,并添加包含我的 TextViews 的水平 LinearLayouts ..然后我有一个字符串列表来查找我需要修改的字符串的索引,然后使用 LinearLayout.getChildAt(int) 搜索它并更新值...
代码:
我有一个字符串列表和一个计数器,显示该字符串出现了多少次...
当字符串是新的时:
我检查字符串是否不是新的(已经在 strList 中)
if(strList.indexOf( sTemp)!=0)
然后执行以下操作:我希望我没有错过任何内容,并且这对您有用..如果您不明白任何内容,请告诉我,我会尝试解释/纠正它。
PS:我认为@abhijeet的适配器解决方案是我的实现的更优雅的版本,但我还没有这样做。
I did something similar.. I just did a list of TextViews (two TextView per row), and i needed to update one TextView in the list.. What i did was a vertical LinearLayout, and add Horizontal LinearLayouts that contained my TextViews.. Then i had a List of strings to look for the index of the one i needed to modify, and then search it with
LinearLayout.getChildAt(int)
and update the value...CODE:
I have a list of strings and a counter that says how many times come this string...
When the String is new:
I check if the String is not new (is already in the strList)
if(strList.indexOf(sTemp)!=0)
and then do as follows:I hope i didn't miss anything and that this works for you.. If you don't understand anything tell me an i try to explain/correct it.
PS: I suppose that the Adapter solution of @abhijeet is a more elegant version of my implementation, but i haven't done it.