package com.asiacove.SmartConcierge;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;
import android.R.style;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import android.view.KeyEvent;
import com.asiacove.SmartConcierge.LoadingActivity;
import com.asiacove.SmartConcierge.GuestRoom.Item;
import com.asiacove.util.MessageFlag;
import com.asiacove.util.StaticSet;
public class FilterListActivity extends LoadingActivity
{
 
 Button btnDone;
 Button btnCancel;
 ImageButton btnCheckBox;
 
 private  ImageView img ;
 private int group_no;
 private String group_name;
 
 private static final String STR_LOG_TAG = "FilterList";
 
 
 ArrayList<Item> mList = new ArrayList<Item>();
 ListView LV;
 private Handler m_Handler;
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.filter_list);
  
  LV = (ListView)findViewById(R.id.lv_filter);
  
  LV.setOnItemClickListener(new AdapterView.OnItemClickListener() 
  {
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    
    Log.w(STR_LOG_TAG,  "GROUP_NO_send: " + mList.get(position).getID());
    
    group_no=mList.get(position).getID();
    group_name=mList.get(position).getTitle();
    
    Log.w(STR_LOG_TAG,  "position: " + position);
    Log.w(STR_LOG_TAG,  "view: " + view);
    
    
    img = (ImageView) LV.getAdapter().getView(position, view, null).findViewById( R.id.iv_img );
     
    Drawable img_ =getResources().getDrawable(R.drawable.checkbox_select_on);
    img.setImageDrawable(img_);
          
          
   }
  });
  initHandler();
  Init(LV, mList, "http://xxx.com/acts29/get_filter_option.php?code=4836&lang="+StaticSet.Lang+ "&icon_os=9317");
 }
 private void initHandler()
 {
  m_Handler = new Handler()
  {
   @Override
   public void handleMessage(Message msg) 
   {
    switch(msg.what) 
    {
    case MessageFlag.ADD_LIST:
     Item item = (Item)msg.obj;
     mList.add(item);
     adapter.notifyDataSetChanged();
     break;     
    }
   }
  };
 }
 protected void varInit() 
 {
     try
     {
         String line; //json 문자열
         int cnt = 0;
        // String[] ret;
         
         while ((line = bReader.readLine())!= null) 
         {
             //ret = line.split("\\|");
    Log.w(STR_LOG_TAG,  "Value: " + line);
      
    
    try {
     Item item;
     //{"NO":"4839","NAME":"\ud55c\uad6d\uc694\ub9ac"}
     
     JSONArray ja = new JSONArray(line);
     
     Log.w(STR_LOG_TAG,  "ja: " + ja.length());
     for(int i=0;i<ja.length();i++){
     
      JSONObject order = ja.getJSONObject(i);
      
     String FilterName =order.getString("NAME");
     
    
    
     item = new Item(Item.middle, Integer.parseInt(order.getString("NO")), FilterName, ImageOperations(this, ""), ""); 
     
     Message msg = m_Handler.obtainMessage();
     msg.obj = item;
     msg.what = MessageFlag.ADD_LIST;
     Thread.sleep(100);
     m_Handler.sendMessage(msg);
     
     Log.d(STR_LOG_TAG,"Add i:"+i);
     }
     
     
     //Log.d(STR_LOG_TAG,"Add CNT:"+cnt);
    } catch (Exception e) {
     Log.e(STR_LOG_TAG, "line : "+line+" e : "+e);
    }
    
           } 
     } catch ( Exception e){
      Log.e(STR_LOG_TAG,  "e : " + e);
     }
 }
 public View getView(final int position, View convertView, ViewGroup parent) 
 {
  
  View v = convertView;
  
        
  if(v == null) {
   int res=0;
   
   Log.d(STR_LOG_TAG, "mList.get(position).Type: "+mList.get(position).Type);
   
   switch (mList.get(position).Type) {
   case Item.middle:
    res = R.layout.filter_list_item;
    break;
   }  
   v = sLayoutInflater.inflate(res,parent,false);
   
  }
  Log.d(STR_LOG_TAG, "GetView position: "+position);
  final Item p = mList.get(position);
  if (p != null) {
   TextView title = (TextView) v.findViewById(R.id.tv_title);
   try {
    title.setText(mList.get(position).getTitle());
   } catch (Exception e) {
   }
  }
 
  return v;
 }
 protected int getViewTypeCount() {
  return 2;
 }
 protected int getItemViewType(int position) {
  return mList.get(position).Type;
 }
 class Item 
 {
  
  static final int start = 0;
  static final int middle = 1;
  static final int end = 2;
  
  int Type;
  private int ID;
  private String title;
  private String content;
  Drawable image = null;
  
  public Item(int _Type, int _ID, String _Title, Drawable _Image, String _Content) 
  {
   this.Type  = _Type;
   this.ID = _ID;
   this.title = _Title;
   this.image = _Image;
   this.content = _Content;
  }
  public int getID() {
   Log.w("DevLog",  "group_getID: " + ID);
   return ID;
  }
  
  public String getTitle() {
   return title;
  }
  
  public Drawable getImage() {
   return image;
  }
  
  public String getContent() {
   return content;
  }
 }
  protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
  super.onApplyThemeResource(theme, resid, first);
  
  // no background panel is shown
 theme.applyStyle(style.Theme_Panel, true);
} 
 
 
 
 
 

그림 처럼 listview 에서 뿌려주고 옆에 imageview 로 선택할 때 이미지 색이 변하도록 하였습니다. 복수 선택이 되어야 하구요.

그런데 클릭할 때 마다 해당 아이템 외의 밑에 스크롤 할 때 다른 아이템도 중복으로 이미지가 변하네요.

어떻게 하면 선택한 것만 이미지가 변할 수 있게할 수 있을까요.

setTag, getTag, getFirstVisiblePosition 이런것들 알아보긴 했는데 별 도움이 안되네요.^^;

고수님들 부탁 드려요.^^