2016-08-04 3 views

Antwort

0

Was Sie tun können, ist die klickbare Eigenschaft Ihrer Rasteransicht zu ändern und dann in die Schaltfläche klicken Zuhörer nur den klickbaren Eigenschaft auf true gesetzt, damit Ihr Code wie folgt aussehen sollte:

lass uns annehmen, dass dies ist Ihre Ansicht:

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

    <Button 
     android:id="@+id/button" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" /> 


    <GridView 
     android:id="@+id/grid" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clickable="false" /> 


</LinearLayout> 

Ihre Aktivität sollte den folgenden Code enthalten:

public class MainActivity extends AppCompatActivity { 

    private Button mButton; 
    private GridView mGridView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mGridView = (GridView) findViewById(R.id.grid); 
     mButton = (Button) findViewById(R.id.button); 

     // if you want to do it with setEnable 

     mGridView.setEnabled(false); 

     mButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       mGridView.setClickable(true); 

       // if you want to toggle then you can use the following code: 
//    mGridView.setClickable(!mGridView.isClickable()); 

       // you can also change the setEnable property and not the clickable 
       mGridView.setEnabled(true); 


      } 
     }); 

    } 
} 
Verwandte Themen