Android Studio:点击时ImageButton不会激活

时间:2016-07-22 16:42:10

标签: java android android-studio

我正在使用此应用程序,目前正在测试它,我不太确定是什么错。当我点击或按住甲板按钮时,绝对没有任何反应。只有在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>

1 个答案:

答案 0 :(得分:2)

如果您使用了$conncet = mysqli_connect('xxx','xxx','xxx','xxx'); function array_sanitize(&$datos) { global $connect; $datos = mysqli_real_escape_string($connect,$datos); }

,则返回true
longclickListener()