android listview的item里面的imageview的点击事件

package com.example.adapter;
import java.io.File;
import java.net.URI;
import java.util.List;
import com.yuayang.lc.R;
import com.yuyang.entity.light;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class loadadapter  extends BaseAdapter {
 private Context context;
 private List<light> list;
 private int Viewitem;
 private LayoutInflater linInflater;
 private ImageView iv;
 private ImageView iv1;
 public loadadapter(Context context, int Viewitem,List<light> list){
  this.context=context;
  this.list=list;
  this.Viewitem=Viewitem;
 }
 @Override
 public int getCount() {
  return list.size();
 }
 @Override
 public Object getItem(int position) {
  return list.get(position);
 }
 @Override
 public long getItemId(int position) {
  return position;
 }
 @Override
 public View getView(final int position, View convertView, ViewGroup parent) {
  Log.i("index", ".......1");
  TextView tv;
  linInflater=(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
           convertView=linInflater.inflate(Viewitem, null);
   iv=(ImageView) convertView.findViewById(R.id.norlight_iv2);
       iv1=(ImageView) convertView.findViewById(R.id.norlight_iv1);
    tv=(TextView) convertView.findViewById(R.id.norlight_tv1);
   if(list.get(position).getStatus()==0){
    iv.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_17));
    iv1.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_o6));
  }else{
   iv.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_10));
   iv1.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_06_1));
  }
    iv.setOnClickListener(new OnClickListener() {  
                    @Override  
                   public void onClick(View v) {  
                     Log.i("index", ""+iv);
                        if(list.get(position).getStatus()==0){  
                         iv.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_10));
                   iv1.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_06_1));
                   list.get(position).setStatus(1);
                   notifyDataSetChanged();
                         }else if(list.get(position).getStatus()==1) {  
                         iv.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_17));
                      iv1.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.p1_jd_ptd_o6));
                      list.get(position).setStatus(0);
                      notifyDataSetChanged();
                          }  
                         return ;  
                    }  
                  }); 
  tv.setText(list.get(position).getLightName());
  return convertView;
 }
 
}

你可能感兴趣的:(android,ListView,imageview,item,点击)