我使用post方法来获取此数组,并且每个帖子的列数都会增加。
"floor":
[
{"no_of_bedroom":"1.5","floor_plotsize_start":"692.00","floor_price_start":"4356832.00"},
{"no_of_bedroom":"2.0","floor_plotsize_start":"1000.00","floor_price_start":"6296000.00"},
{"no_of_bedroom":"2.0","floor_plotsize_start":"1029.00","floor_price_start":"6478584.00"},
{"no_of_bedroom":"2.0","floor_plotsize_start":"1132.00","floor_price_start":"7127072.00"},
{"no_of_bedroom":"3.0","floor_plotsize_start":"1390.00","floor_price_start":"8751440.00"},
{"no_of_bedroom":"3.0","floor_plotsize_start":"4901.00","floor_price_start":"40801320.00"}
]
如何在android中使用动态textview进行显示?
JSONArray jsonarray;
jsonarray = jsonobject.getJSONArray("floor");
{
//How to proceed by using dynamic textview?
}
提前致谢
答案 0 :(得分:1)
我猜你可以创建一个listview,其中包含你想要显示的项目的textview
我的建议是使用循环来获取每个对象并将其放在listview
中伪代码:
for(int i=0; i< jsonarray.size(); i++){
list.add(jsonarray.getJSONObject(i).getString("no_of_bedroom")); //just an example to check the details of no_of_bedroom key and add it inside the
}
//using list adapter HERE to display the item the TextView
您可以尝试一下并向我们提供有关您希望如何做的更多信息。
答案 1 :(得分:0)
您可以动态创建所需的文本视图,然后将其添加到主布局并显示。以下是一个小提示:
JSONArray jArray = jsonobject.getJSONArray("floor");
for(int i=0; i < jArray.length(); i++)
{
TextView textview = new TextView();
textview.setText(""); //your own text
textview.setTextColor(Color.parseColor("#000000")); //your own color
//And now add this textview to your main layout
yourlayout.addView(textview);
}
答案 2 :(得分:0)
试试这个
JSONArray jArray = jsonobject.getJSONArray("floor");
for(int i=0; i < jArray.length(); i++)
{
TextView textview = new TextView(this);
textview.setText(""); //your own text
layoutname.addView(textview);
}