我試圖從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