0

I have generated a Listview using a SimpleAdapter. I want to set different pictures for each row of the ListView. I have done the following coding, but my image sets only on the first row. how to set pictures for the remaining row. Please explain me step by step.

My codes are as below:

Contacts extends Fragment

 ArrayList<HashMap<String, String>>val=new ArrayList<HashMap<String,String>>();
 val=db.getTaskSent(name);
  ListAdapter k=new SimpleAdapter(getActivity(),val,R.layout.senttaskdata,new String[]{"rname","heading","desc","id","path","receiver","sender"},new int[]{R.id.textView1,R.id.textView2,R.id.textView3,R.id.hide1,R.id.hide2,R.id.hide3,R.id.hide4})
  {

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final View v = super.getView(position, convertView, parent);
        TextView picpath=(TextView)v.findViewById(R.id.hide2);
        ImageView picture=(ImageView)v.findViewById(R.id.imageView1);
        String p=picpath.getText().toString();
         File f = new File(p);
        //ImageView mImgView1 = (ImageView)findViewById(R.id.imageView2);
        Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
        picture.setImageBitmap(bmp);

        return super.getView(position, convertView, parent);
    }

  };
  sent.setAdapter(k);
1
  • 2
    just return v instead of return super.getView(position, convertView, parent); Commented Apr 24, 2014 at 7:48

1 Answer 1

1
ArrayList<HashMap<String, String>>val=new ArrayList<HashMap<String,String>>();
 val=db.getTaskSent(name);
  ListAdapter k=new SimpleAdapter(getActivity(),val,R.layout.senttaskdata,new String[]{"rname","heading","desc","id","path","receiver","sender"},new int[]{R.id.textView1,R.id.textView2,R.id.textView3,R.id.hide1,R.id.hide2,R.id.hide3,R.id.hide4})
  {

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final View v = super.getView(position, convertView, parent);
        TextView picpath=(TextView)v.findViewById(R.id.hide2);
        ImageView picture=(ImageView)v.findViewById(R.id.imageView1);
        String p=picpath.getText().toString();
         File f = new File(p);
        //ImageView mImgView1 = (ImageView)findViewById(R.id.imageView2);
        Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
        picture.setImageBitmap(bmp);

        return v;
    }

  };
  sent.setAdapter(k);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.