Question

I have two ListView and one adapter on them for previous and future items.

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);

I know that solutionDesignSteps contains different items. But on screen and in getView I get list the same items.

Here I just fill steps list (just for test)

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;
    }

My adapter class

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;

        }

    }

Can you help me to understand the problem?

Was it helpful?

Solution

It seems that in the adapter you only use the same step object Step step = stepsList.get(0); it should be something like Step step = stepsList.get(position);

OTHER TIPS

Replace

 Step step = stepsList.get(0);

with

 Step step = stepsList.get(position);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top