我有适配器来呈现数据的问题。我有一个对象,里面有很少的列表,需要显示来自它们的数据。我需要提出:
日期 * 航班号 *持续时间 *带货币的常规票价
这是我的模型类:
public class Currency implements Serializable {
private String currency;
private Integer currPrecision;
private List<Trip> trips = null;
private String serverTimeUTC;
public class Trip {
private String origin;
private String originName;
private String destination;
private String destinationName;
private List<Date> dates = null;
public class Date {
private String dateOut;
private List<Flight> flights = null;
public class Flight {
private String flightNumber;
private List<String> time = null;
private List<String> timeUTC = null;
private String duration;
private Integer faresLeft;
private String flightKey;
private Integer infantsLeft;
private RegularFare regularFare;
private BusinessFare businessFare;
private LeisureFare leisureFare;
我尝试使用可扩展列表适配器处理但没有成功。这是我的适配器类:
public class MyExpandableAdapter extends BaseExpandableListAdapter {
private Activity activity;
private ArrayList<ArrayList<Flight>> childtems;
private LayoutInflater inflater;
private ArrayList<Date> parentItems;
private ArrayList<Flight> child;
public MyExpandableAdapter(ArrayList<Date> parents,ArrayList<ArrayList<Flight>> childern) {
this.parentItems = parents;
this.childtems = childern;
}
public void setInflater(LayoutInflater inflater, Activity activity) {
this.inflater = inflater;
this.activity = activity;
}
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
child = (ArrayList<Flight>) childtems.get(groupPosition);
TextView textView = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.result_row, null);
}
textView = (TextView) convertView.findViewById(R.id.listTitle);
textView.setText(child.get(childPosition).getDuration());
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
}
});
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.result_row, null);
}
((CheckedTextView) convertView).setText(parentItems.get(groupPosition).getDateOut());
((CheckedTextView) convertView).setChecked(isExpanded);
return convertView;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public int getChildrenCount(int groupPosition) {
return ((ArrayList<Flight>) childtems.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public int getGroupCount() {
return parentItems.size();
}
@Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
@Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
我的活动课程:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
ButterKnife.bind(this);
if(getIntent() != null) {
Intent intent = getIntent();
String currencyString = intent.getStringExtra("Currency");
Gson gson = new Gson();
Currency currency = gson.fromJson(currencyString, Currency.class);
trips = new ArrayList<>();
trips = currency.getTrips();
for(Trip trip :trips) {
ArrayList<Date> date = trip.getDates();
dates=date;
for(Date dateFlight: dates) {
flights.add(dateFlight.getDateOut());
}
}
adapter = new MyExpandableAdapter(dates,flights);
mTripsRv.setAdapter(adapter);
}
先谢谢你的帮助!! :)