0

i want to change particular listview images when click on nect and prev button but Changed all list view images when click on next and prev button

public class ListAdapter extends ArrayAdapter<String>{

    Context context;
     String imgurl;
     String[] imageUrls;
     int i=1;
     ViewHolder holder = null;

    ArrayList<String> strimgview,strstreetname,strLocation,strSquarefootage,strPrice,strPosted,strURL,strId;
     ImageLoader imageLoader = ImageLoader.getInstance();
     DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
                    .cacheOnDisc(true).resetViewBeforeLoading(true).build();
    public ListAdapter(Context context,ArrayList<String> strimgview, ArrayList<String> strstreetname, 
            ArrayList<String> strLocation,ArrayList<String> strSquarefootage,
            ArrayList<String> strPrice,ArrayList<String> strPosted,
            ArrayList<String> strId,ArrayList<String> strURL)
    {
        super(context, R.layout.propertyrow,strstreetname);
        this.context= context;
        this.strimgview= strimgview;
        this.strstreetname= strstreetname;
        this.strLocation= strLocation;
        this.strSquarefootage= strSquarefootage;
        this.strPrice= strPrice;
        this.strPosted= strPosted;
        this.strURL= strURL;


    }
     public View getView(int position, View convertView, ViewGroup parent) {
         LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            View row = convertView;

            if (row == null) {
               row=mInflater.inflate(R.layout.propertyrow, parent,false);

           holder = new ViewHolder();
           holder.imgProperty =(ImageView) row.findViewById(R.id.npTupleImage);

           holder.txtStreetName= (TextView) row.findViewById(R.id.npTupleProjectName);
           holder.txtLocation= (TextView) row.findViewById(R.id.npTupleBuilder);
           holder.txtSquareFotage= (TextView) row.findViewById(R.id.npTupleProjectAddress);
           holder.txtPrice =(TextView) row.findViewById(R.id.npTupleProjectDistance);
           holder.txtprev =(TextView) row.findViewById(R.id.prev);
           holder.txtnext =(TextView) row.findViewById(R.id.next);
         //txtprev.setVisibility(View.INVISIBLE);
         //txtnext.setVisibility(View.INVISIBLE);
           holder.imglike= (ImageView) row.findViewById(R.id.unsavebtn);
           holder.imglike.setVisibility(View.INVISIBLE);
            row.setTag(holder);
            }
            else {
                holder = (ViewHolder) row.getTag();
            }
        // txtposted.setText("EnteredDate :"+strPosted.get(position));
           holder.txtStreetName.setText("Street Name :"+strstreetname.get(position));
           holder.txtLocation.setText("Location :"+strLocation.get(position));
           holder.txtSquareFotage.setText("SquareFootage :"+strSquarefootage.get(position));
           holder.txtPrice.setText("Price :$"+strPrice.get(position));
           holder.imgProperty.setTag(position);
         // Log.d("Img",strimgview.get(position));
         try{
            // ArrayList<String> imgurl=new ArrayList<String>();
              imgurl= ""+strimgview.get(position);
              imageUrls=imgurl.split("\\|\\|");
              for(int j=0;j<imageUrls.length-1;j++)
                  imageLoader.displayImage(imageUrls[i], holder.imgProperty, options);

         }
         catch(Exception e)
         {
             Toast.makeText(context, "Load"+e, Toast.LENGTH_LONG).show();
         }

         holder.imglike.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //Toast.makeText(context, "Want to save", Toast.LENGTH_LONG).show();

            }
        });

         holder.txtprev.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub


                try{

                  if(i!=1)
                  {
                      i--;
                      imageLoader.displayImage(imageUrls[i], holder.imgProperty, options);
                  Log.d("imageUrlnew ",imageUrls[i]);

                  }


                 }
                 catch(Exception e)
                 {
                    // Toast.makeText(context, "next"+e, Toast.LENGTH_LONG).show();

                 }

                 notifyDataSetChanged();
            }
        });

         holder.txtnext.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                     try{


                          if((i<imageUrls.length-1))
                          {
                              i++;
                              imageLoader.displayImage(imageUrls[i], holder.imgProperty, options);

                          Log.d("imageUrlnew ",imageUrls[i]);

                          }
                         }
                         catch(Exception e)
                         {
                             // Toast.makeText(context, "prev"+e, Toast.LENGTH_LONG).show();
                         }
                     notifyDataSetChanged();
                }
            });

         return row;


     }

      class ViewHolder {
            ImageView imgProperty;
            TextView txtprev,txtnext;
            TextView txtStreetName;
            TextView txtLocation;
            TextView txtSquareFotage;
            TextView txtPrice;
            ImageView imglike;
            ProgressBar progressBar;
      }

}

Please help me how can fix this issue

Thanks In Advance

enter image description here

Renu Singh
  • 111
  • 3
  • 10

1 Answers1

0

this is not a perfect solution if it works according to ur requirment. then update the solution withot switch.

lstviewHomeList.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {

                switch (position) {
                case 0:
                    Button btnprev = (Button ) arg1.findViewById(R.id.button_id);
                      //same for image and any widgetn your adapter layout xml
                    btnprev.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            //do what u want

                        }
                    });

                    break;

                default:
                    break;
                }
            }

        });
M S Gadag
  • 2,057
  • 1
  • 12
  • 15