我试图从JSON
数据创建一个自定义Adapter
,我可以创建装在每个记录一列中的所有数据ListView
但我想每个值是在它的上一行。样品JSON
JSON数据ListView中使用自定义适配器
{
"outages": [
{
"outagnumber": "567273",
"impact": "half a block",
"status": "almost complete",
"timestamp": "07-19-2015 12:00:00am"
},
{
"outagnumber": "567243",
"impact": "whole block",
"status": "whating on crew",
"timestamp": "07-19-2015 11:00:00am"
},
]
}
实现此目的的最佳方法是什么?
适配器
public class CustomListOutageAdapter extends ArrayAdapter{
private final Activity context;
private final LinkedList<HashMap<String, String>> itemname;
public CustomListOutageAdapter(Activity context, LinkedList<HashMap<String, String>> itemname) {
super(context, R.layout.mylistoutagedetails, itemname);
// TODO Auto-generated constructor stub
this.context = context;
}
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.mylistoutagedetails, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.name);
txtTitle.setText(itemname.get(position).toString());
return rowView;
};
}
你是说你想要这个:“outagnumber”:“567273”在它自己的列表中,并且这个:“impact”:在它自己的列表中的“half a block”,并且为你的数组中的每个json对象做这件事?对不起,我不明白你想要实现什么 – TooManyEduardos
@TooManyEduardos是的,每个都在列表中的行中。 – Dwill
但是你的问题是什么?你在问如何解析json,或者你在问如何为列表视图制作UI? – TooManyEduardos