gpt4 book ai didi

android - 具有不同对象的 ListView 和适配器

转载 作者:行者123 更新时间:2023-11-29 21:06:05 25 4
gpt4 key购买 nike

<分区>

我有以下问题让我发疯,我有 1 个 json 文件,其中有 2 种不同的数据,我需要显示这个一个 ListView 上的数据,每个 ListView 都有标题分隔,我还需要在适配器中执行此操作,在到达那里之前,我还需要将数据合并到一个对象中,以将其传递给适配器。

数据示例

<LiveSales>
<Car_Sales_Response>
<Name>Name</Name>
<AwName>Abbrv Name</AwName>
<Number>1</Number>
<StartTime>2014-02-12T19:10:00+11:00</StartTime>
<Code>e3029fc698fe35b61sdfkjhs</Code>
<ChannelName>Online</ChannelName>
</LiveSales>

<NowSales>
<ArrayOfSales xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Car Id="987123" SportId="1" CompId="109" Name="New Name" MatchDate="2014-07-05T00:00:00+10:00" StartTime="2014-07-05T13:47:00+10:00" TypeName="Racing" DisplayPriority="0" Markets="2"></Car>
<Car Id="982323" SportId="1" CompId="102" Name="New Name 2" MatchDate="2014-07-05T00:00:00+10:00" StartTime="2014-07-05T13:47:00+10:00" TypeName="Racing" DisplayPriority="0" Markets="2"></Car>
</ArrayOfSales>
</NowSales>

这是我的适配器,我还没有弄好。

public class CarAdapter extends ArrayAdapter<Object> {

public CarAdapter ( Context context , int textViewResourceId, ArrayList<Object> items) {
super(context, textViewResourceId, items);
}

public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
// Create holder
ViewHolder viewHolder = null;

if (view == null) {
view = mInflater.inflate(R.layout.row, null);
viewHolder = new ViewHolder();

viewHolder.date = (TextView) view.findViewById(R.id.textViewDate);
viewHolder.names = (TextView) view.findViewById(R.id.textViewName);
// more here
} else {
viewHolder = (ViewHolder) view.getTag();
}

// Here I'm stuck
Object a = (Object) getItem(position);

return view;

}
}

我是如何解析数据的,两个 url 是一样的

public static ArrayList<LiveSale> getUpcomingMatches() {
ArrayList<LiveSale> items = null;

try {
Document doc = App.getXMlDocument("URL");

items = CarSales.parse(doc);
return items;

} catch (Exception e) {
e.printStackTrace();
}

return items;
}

public static ArrayList<NowSale> getLiveMatches() {

ArrayList<NowSale> items = null;

try {
Document doc = App.getXMlDocument("URL");
items = parse(doc);
return items;

} catch (Exception e) {
e.printStackTrace();
}

return items;
}

PS 我正在使用 fragment 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com