I'm doing a project (a memory game) with this tutorial link I'm doing it a little different Create a menu_activity that says the name of the game and an image with the Play icon. This brings us to the second activity, where is the problem I have 3 images which indicate the difficulty.
In the project I do not see any error, I run but when going to my LevelActivity and click on the difficulty, for example to go EasyActivity (and to show the memorama) the application does nothing. I do not know much about it but I think it's a problem when implementing OnClick. Try to create the OnClick as I did with the main menu:
public void goGame(View view){
Intent intent = new Intent(this, LevelActivity.class);
startActivity(intent);
}
}
But when you do this and click on the difficulty the application is closed.
I show you part of the code.
The LevelActivity
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class LevelActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
}
}
The XML of the image that tells us the difficulty
<ImageView
android:id="@+id/easylevel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/facil"
android:layout_gravity="center"
/>
I have my EasyActivity class
public class EasyActivity extends AppCompatActivity implements
View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_easy);
// I skipped the code that I think does not affect the problem
for (int r = 0; r < numRows; r++){
for(int c = 0; c < numColumns; c++){
MemoryButton tempButton = new MemoryButton(this, r, c,
buttonGraphics[buttonGraphicLocations[r * numColumns + c]]);
tempButton.setId(View.generateViewId());
tempButton.setOnClickListener(this);
buttons[r * numColumns + c] = tempButton;
gridLayout.addView(tempButton);
}
}
@Override
public void onClick(View view) {....}