Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Studio:ImageButton';轻触时未激活_Java_Android_Android Studio - Fatal编程技术网

Java Android Studio:ImageButton';轻触时未激活

Java Android Studio:ImageButton';轻触时未激活,java,android,android-studio,Java,Android,Android Studio,我正在开发这个应用程序,目前正在测试它,我不太确定出了什么问题。当我点击或按住甲板按钮时,绝对不会发生任何事情。logcat中唯一显示的是触摸事件。我认为我的格式可能有问题,但由于这是我第一次使用Java(过去只在微处理器类中使用汇编),我不确定它可能是什么 编辑:删除了许多与问题无关的额外代码 下面是MainActivity.java public class MainActivity extends AppCompatActivity { int i=0; int VOA=

我正在开发这个应用程序,目前正在测试它,我不太确定出了什么问题。当我点击或按住甲板按钮时,绝对不会发生任何事情。logcat中唯一显示的是触摸事件。我认为我的格式可能有问题,但由于这是我第一次使用Java(过去只在微处理器类中使用汇编),我不确定它可能是什么

编辑:删除了许多与问题无关的额外代码

下面是MainActivity.java

 public class MainActivity extends AppCompatActivity {
    int i=0;
    int VOA=0;
    int VOB=0;
    int [] c ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};



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


// The Draw Control for the Deck. It will only draw if it is in it's 0 state
        ImageButton Deck =(ImageButton)(findViewById(R.id.Deck));
        assert Deck != null;
        Deck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if( VOA==0){
                    VOA=c[i];
                    i=i+1;


                } else if (VOB==0){
                    VOB=c[i];
                    i=i+1;

                }

            }
        });

// Uses Collections shuffle to shuffle c
        Deck.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                List c= new ArrayList();
                Collections.shuffle(c);


                return false;
            }});


//Discard for Objective A by setting it to 0 and thus updating it's case statement.
        ImageButton ObjectiveA =(ImageButton)(findViewById(R.id.ObjectiveA));
        assert ObjectiveA != null;
        ObjectiveA.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                VOA=0;
                return false;
            }
        });



//Discard for Objective B by setting it to 0 and thus updating it's case statement.
        ImageButton ObjectiveB =(ImageButton) (findViewById(R.id.ObjectiveB));
        assert ObjectiveB != null;
        ObjectiveB.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                VOB=0;
                return false;

            }
        });

        }
    }
}
下面是activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="gallostsp.darkagedeck.MainActivity"
    android:background="@drawable/background"
    android:screenOrientation="landscape">



    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Deck"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/VerticalCenterLine"
        android:layout_toStartOf="@+id/VerticalCenterLine"
        android:background="@drawable/deck"
        android:contentDescription="@string/objectives_deck"
        android:clickable="true"
        android:longClickable="true" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ObjectiveA"
        android:background="@drawable/objectivearea"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_toRightOf="@+id/VerticalCenterLine"
        android:layout_toEndOf="@+id/VerticalCenterLine"
        android:layout_above="@+id/ObjectiveB"
        android:contentDescription="@string/objective_a"
        android:longClickable="true"
        android:clickable="false" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ObjectiveB"
        android:layout_below="@+id/HorizontalCenterLine"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:background="@drawable/objectivearea"
        android:layout_toRightOf="@+id/VerticalCenterLine"
        android:layout_toEndOf="@+id/VerticalCenterLine"
        android:layout_alignParentBottom="true"
        android:contentDescription="@string/objective_b"
        android:longClickable="true"
        android:clickable="false" />


</RelativeLayout>

如果您使用了
longclickListener()


建议阅读:感谢这一帮助,这样我就可以知道按钮实际上在工作,我将不得不对我的代码进行更多的测试,以找出它到底出了什么问题。现在谢谢你。
   Deck.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                List c= new ArrayList();
                Collections.shuffle(c);


                return true; // change to true
            }});