Question

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);
Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top