0

我正在使用 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?
}

提前致谢

4

3 回答 3

1

我想您可以使用要显示的项目的文本视图创建一个列表视图

我的建议是使用循环来获取每个对象并将其放在列表视图中

伪代码:

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

您最好尝试一下,并为我们提供更多关于您希望如何操作的信息。

于 2013-08-28T06:04:30.340 回答
0

try this

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);
}
于 2013-08-28T06:38:51.487 回答
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);
}
于 2013-08-28T06:33:14.097 回答