0
私はGridviewの項目から値を選択する簡単なゲームを作ろうとしています。しかし、私はその値がちょうど再生ボタンを押した後にクリック可能にしたいと思っています。私は再生ボタンを押していないとどこでもクリックできません。どうやってやるの?あなたは何ができるかボタンを押す前にGridviewの領域を無効にする方法は?
私はGridviewの項目から値を選択する簡単なゲームを作ろうとしています。しかし、私はその値がちょうど再生ボタンを押した後にクリック可能にしたいと思っています。私は再生ボタンを押していないとどこでもクリックできません。どうやってやるの?あなたは何ができるかボタンを押す前にGridviewの領域を無効にする方法は?
ので、あなたのコードは次のようになります。あなたのグリッドビュー のクリック可能なプロパティを変更し、ボタンのクリックリスナーにだけ真 にクリック可能なプロパティを設定することです:
のがあることを想定してみましょうこれはあなたのビューである:
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);
}
});
}
}
:
<?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>
あなたの活動は、次のコードが含まれている必要があります