Reputation: 11
I'm working on this App and currently testing it and I'm not quite sure what's wrong. As I tap or hold the Deck Button absolutely nothing happens. Only thing showing up in logcat are Touch Events. I think it might be something wrong with my formatting, but since this is my first time with Java (Only have used assembly for a microprocessors class in the past) I am not sure what it could be.
EDIT: Removed a lot of the extra code unrelated to the problem per suggestion
Here is the 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;
}
});
}
}
}
Here is the activity_main.xml as well
<?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>
Upvotes: 1
Views: 35
Reputation: 8149
Return true if you consumed the longclickListener()
Deck.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
List c= new ArrayList();
Collections.shuffle(c);
return true; // change to true
}});
Upvotes: 2