我有两个ListView和一个适配器用于前一个和将来的项目。
StepAdapter quoteStepAdapter = new StepAdapter(RequestDetail.this,
R.layout.lv_step, quoteInitiationStepsList);
ListView qouteStepListView = (ListView) findViewById(R.id.quote_step_list);
qouteStepListView.setAdapter(quoteStepAdapter);
List<Step> solutionDesignSteps = initSolutionDesignSteps();
StepAdapter solutionDesignStepAdapter = new StepAdapter(RequestDetail.this,
R.layout.lv_step, solutionDesignSteps);
ListView solutionDesignListView = (ListView) findViewById(R.id.solution_design_step_list);
solutionDesignListView.setAdapter(solutionDesignStepAdapter);
我知道solutionDesignSteps
包含不同的项目。但是在屏幕和getView
中我列出了相同的项目。
这里我只填写步骤列表(仅供测试)
private List<Step> initSolutionDesignSteps(){
List<Step> steps = new ArrayList();
steps.add(new Step("desc2", 2, "Started", new Date("27 Feb 2014")));
steps.add(new Step("desc3", 3, "", new Date("28 Feb 2014")));
steps.add(new Step("desc4", 4, "Started", new Date("02 Mar 2014")));
steps.add(new Step("desc5", 5, "Started", new Date("02 Mar 2014")));
return steps;
}
我的适配器类
private static class StepAdapter extends ArrayAdapter<Step> {
private Context context;
private int resourceId;
private List<Step> stepsList;
public StepAdapter(Context context, int resourceId, List<Step> steps) {
super(context, resourceId, steps);
this.context = context;
this.resourceId = resourceId;
this.stepsList = steps;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(LAYOUT_INFLATER_SERVICE);
View rowView = layoutInflater.inflate(resourceId, parent, false);
Step step = stepsList.get(0);
TextView orderedNumber = (TextView) rowView
.findViewById(R.id.step_number);
orderedNumber.setText(step.getOrderedNumber() + ". ");
TextView description = (TextView) rowView
.findViewById(R.id.step_description);
description.setText(step.getDescription());
Drawable drawable = null;
Resources resources = context.getResources();
if ("Complete".equals(step.getStatus())) {
drawable = resources.getDrawable(R.drawable.ic_check);
} else if ("Started".equals(step.getStatus())) {
drawable = resources.getDrawable(R.drawable.ic_started);
}
if(drawable != null){
ImageView stepStatus = (ImageView) rowView
.findViewById(R.id.step_status);
stepStatus.setImageDrawable(drawable);
}
TextView stepUpdatedDate = (TextView) rowView
.findViewById(R.id.status_updated);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(resources.getString(R.string.date_format));
String stepUpdatedDateStr = simpleDateFormat.format(step
.getUpdatedDate());
stepUpdatedDate.setText(stepUpdatedDateStr);
return rowView;
}
}
你能帮我理解这个问题吗?
答案 0 :(得分:3)
在适配器中,您似乎只使用相同的步骤对象Step step = stepsList.get(0);
它应该是Step step = stepsList.get(position);
答案 1 :(得分:0)
替换
Step step = stepsList.get(0);
与
Step step = stepsList.get(position);