2015-02-09 44 views
-1

我有一個圖像按鈕和一個圖像視圖。我試圖獲得懸停主題,就像用戶單擊某個項目時,會在項目上懸停圖像,這意味着他檢查了該項目。我的XML:當視圖重新加載到適配器時,圖像變得不見了

佈局1:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 


    <ImageButton 
     android:id="@+id/fetchedImageObj" 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     android:layout_weight="1" 
     android:scaleType="centerInside" 
     android:src="@drawable/test" 
     android:background="@drawable/image_selector" 
     android:clickable="true" 
     android:padding="0dp" 
     /> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:id="@+id/hoverImage" 
      android:layout_width="fill_parent" 
      android:layout_height="200dp" 
      android:scaleType="centerInside" 
      android:src="@drawable/correct" 
      android:visibility="gone"/> 
    </RelativeLayout> 

這是我的適配器上我試圖做任務。但whenerver我選擇一個項目,向下滾動消失或切換到其他對象的問題

適配器:

public class FetchItemAdapter extends BaseAdapter { 

    private Activity myContext; 
    private LayoutInflater inflater; 
    public FetchModel fetchModel; 
    private boolean check_click=false; 

    public FetchItemAdapter(Activity context,FetchModel fetchModel) 
    { 
     this.myContext=context; 
     inflater = context.getLayoutInflater(); 
     this.fetchModel = fetchModel; 

    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return this.fetchModel.images.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 
private static class ViewHolder { 


     ImageButton fetchedImageObj; 
     ImageView selection; 

} 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     System.out.println("get View"); 



     final ViewHolder viewHolder = new ViewHolder(); 


     convertView = inflater.inflate(com.yolove.R.layout.fetched_images_row,null); 

     //viewHolder = new ViewHolder(); 
     viewHolder.fetchedImageObj = (ImageButton) convertView.findViewById(com.yolove.R.id.fetchedImageObj); 
     viewHolder.selection=(ImageView)convertView.findViewById(com.yolove.R.id.hoverImage); 


     convertView.setTag(viewHolder); 


     ImageLoader.getInstance().displayImage(fetchModel.images.get(position).imageurl,viewHolder.fetchedImageObj); 


     viewHolder.fetchedImageObj.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       if(check_click==false) 
       { 
        viewHolder.selection.setVisibility(View.VISIBLE); 
        check_click=true; 


       } 
       else 
       { 
        viewHolder.selection.setVisibility(View.GONE); 
        check_click=false; 
       } 

      } 
     }); 

      return convertView; 
    } 

} 

我已經作出了最終的持有人得到viewholder.selection對象。

+0

爲什麼投票? – Fay007 2015-02-09 08:56:24

+0

你應該使用查看持有人模式獲取視圖 – 2015-02-09 09:19:01

+0

什麼是模式? – Fay007 2015-02-09 09:20:47

回答

1

在我看來,您需要爲您的圖像背景製作一個選擇器xml,並將圖像視圖設置爲在xml文件中可見。

+0

如何使視圖在選擇器xml中可見 – Fay007 2015-02-09 09:08:11

+0

您需要在可繪製文件夾中生成選擇器xml,如 – 2015-02-09 13:47:52

+0

<?xml version =「1.0」encoding =「utf-8」?> 2015-02-09 13:48:24