开发者

Question about creating GUIS "dynamically" on Android

开发者 https://www.devze.com 2023-01-24 17:39 出处:网络
I\'m trying to make an android app (I\'m new in the Android programming world), and I\'m having problems creating the GUI.

I'm trying to make an android app (I'm new in the Android programming world), and I'm having problems creating the GUI.

The point is that I get information of some data that is divided in days... The problem is that I don't know, until I retrieve the information, how many days the GUI should display.

http://img574.imageshack.us/img574/3787/mainscreen.jpg

The grey part will be a TextView, and, also, the black part will be another TextView with multiple lines.

So, the point is, how can I do to have multiple TextView's without knowing before the exact number? I suppose that I can't declare them in the layout.xml

The only solution that I've been thinking about is to create in the layout 7 pairs of TextView and, when I know the exact number, just use what I have to, and don't use the others... (It's a bad solution)

开发者_如何学运维

What do you suggest?

Thank you for your answers!


You should create a ListView, which inflates TextView for the items you have.

You can use this example of how to create sectioned ListView, which will look exactly like you want.


I'm not familiar with Android, so other people may offer better, more specific advice.

In the environments I'm familiar with, the problem of displaying an unknown number of items is solved by using not a series of display elements for each data item but a list control. The list component will display as many items as you give it, and can usually be modified to have different appearance for different data, so you're flexible in making it as pretty as you want.


Well you can consider this one also,

  • Create a table layout in XML, give it a id: TableLayout table=(TableLayout)findViewById(r.id. ....)
  • Create dynamic TextViews using: TextView day=new TextView(this); day.setText(day name);
  • Now add this text view to your table layout : table.addView(day);
  • Run the code for textView creation and addition to table in loop

Hope this helps...............

0

精彩评论

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

关注公众号