2015-02-09 38 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

相关问题