2017-04-10 64 views
0

我想制作一个FileExplorer。 在custom_list.xml中,我定义了一个CheckBox(Visible = GONE),一个图像和2个textViews。我想要的是,当我执行LongItemClick时,列表中的每个CheckBox都将View.VISIBLE的可见性更改为View.VISIBLE。 我已经用getChildCount()试过了。但问题是,它只适用于绘制,而不是当你滚动下来。如何将CustomListView中的所有CheckBox从GONE更改为VISIBLE?

那么如何通过在listview中对物品进行长按来显示所有CheckBox?

customAdapter

adapter = new CustomListAdapter(arrCurrentDirFolders, subheadListFolders, imgList, getActivity().getApplicationContext()); 

    listView.setAdapter(adapter); 

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { 

     @Override 
     public boolean onItemLongClick(AdapterView<?> arg0, View arg1, 
             int pos, long id) { 
      // TODO Auto-generated method stub 

      HERE I WANT TO SET VISIBILITY = VISIBLE FOR ALL CHECKBOXES 

      /*for(int i = 0; i < listView.getChildCount(); i++) { 
       listView.getChildAt(i).findViewById(R.id.checkBox_checkDir).setVisibility(View.VISIBLE); 
      }*/ 

      return true; 
     } 
    }); 

    // set the list item on click listener 
    listView.setOnItemClickListener(newAdapterView.OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 

     Log.v("Position: ", position+" pressed"); 

     } 
    }); 

custom_list.xml

<?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" > 

    <CheckBox 
     android:id="@+id/checkBox_checkDir" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="20dp" 
     android:visibility="gone" /> 

    <ImageView 
     android:id="@+id/img_customlist_icon" 
     android:layout_marginLeft="5dp" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     android:layout_centerVertical="true" 
     android:layout_toEndOf="@+id/checkBox_checkDir" /> 

    <TextView 
     android:id="@+id/headingText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginLeft="5dp" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:layout_alignTop="@+id/img_customlist_icon" 
     android:layout_toEndOf="@+id/img_customlist_icon" /> 

    <TextView 
     android:id="@+id/subHeadingText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_below="@+id/headingText" 
     android:layout_alignStart="@+id/headingText" /> 

</RelativeLayout> 

List all Elements from InternalStorage LongClick on an Element

回答

0

你可以很容易只是把一个名为isCheckBoxVisible参数传递的列表对象到适配器,这将是假的,一旦你长按make for循环,并更新列表isCheckBoxVisible为true,然后notifydatasetchanged();在customadapter检查isCheckBoxVisible如果true设置复选框为可见如果false设置复选框去了

相关问题