2014-07-18 68 views
0

我已经通过添加一些额外的视图来修改此tutorial,我现在要做的是将图像视图的可见性设置为仅在最后一组中隐藏,在expandablelistview中隐藏最后一组视图

集团布局是这样的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" > 

    <TextView 
     android:id="@+id/laptop" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:paddingLeft="25dp" /> 

    <CheckBox 
     android:id="@+id/checkBox1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:focusable="false" 
     android:text=" " /> 

    <ImageView 
     android:id="@+id/delete" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/checkBox1" 
     android:layout_toLeftOf="@+id/checkBox1" 
     android:contentDescription="@string/app_name" 
     android:src="@android:drawable/ic_delete" /> 

</RelativeLayout> 

,并在那里我试图隐藏视图中的代码是这样

public View getGroupView(final int groupPosition, boolean isExpanded, 
     View convertView, ViewGroup parent) { 
    String laptopName = (String) getGroup(groupPosition); 
    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.group_item, null); 
    } 
    TextView item = (TextView) convertView.findViewById(R.id.laptop); 
    item.setTypeface(null, Typeface.BOLD); 
    item.setText(laptopName); 
    ImageView delete = (ImageView) convertView.findViewById(R.id.delete); 

    if (groupPosition == getGroupCount()-1) { 
     delete.setVisibility(View.INVISIBLE); 
    } 


     delete.setOnClickListener(new OnClickListener() { 
       int gpos = groupPosition; 
      public void onClick(View v) { 
       AlertDialog.Builder builder = new AlertDialog.Builder(
         context); 
       builder.setMessage("Do you want to remove?"); 
       builder.setCancelable(false); 
       builder.setPositiveButton("Yes", 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, 
            int id) { 
          } 
         }); 
       builder.setNegativeButton("No", 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, 
            int id) { 
           dialog.cancel(); 
          } 
         }); 
       AlertDialog alertDialog = builder.create(); 
       alertDialog.show(); 
      } 
     }); 


    return convertView; 
} 

仅滚动列表后,问题发生时,厕所Ks喜欢它与视图的回收有关,我不知道我该如何处理它,你能帮助我吗?

回答

1

你是正确的,你的意见被回收,这就是为什么你必须明确地将视图设置为VISIBLE或不是每次你返回视图。尝试这样的事情。

if (groupPosition == getGroupCount()-1) { 
    delete.setVisibility(View.GONE); 
}else { 
    delete.setVisibility(View.VISIBLE); 
} 
相关问题