In general, there are buttons that launch a certain level, how to make it so that level 2 (button 2) is unlocked when the user types a certain amount of points at level 1. Give a hint, I'm just new to Android development! The problem is that I cannot count points from level 1, because all the time a new bandl is being created, and because of this I can’t write a method that blocks Level 2!

public class CategoryActivity extends ActionBarActivity { private Toolbar toolbar; private DatabaseHandler databaseHandler; private Button btn1; private Button btn2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_category); toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("Choose Category"); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave); } }); btn1 = (Button) findViewById(R.id.button1); btn1.setText("Marvel".toString()); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(CategoryActivity.this, BeginTestActivity.class); Bundle b = new Bundle(); databaseHandler = new DatabaseHandler(btn1.getContext()); b.putString("category", btn1getText().toString()); if (databaseHandler.getScoreForCategory(btn1.getText().toString()) != null) { b.putString("best_score", databaseHandler.getScoreForCategory(btn1.getText().toString()).getScore()); } else { b.putString("best_score", "0"); } intent.putExtras(b); startActivity(intent); overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right); } }); btn2 = (Button) findViewById(R.id.button2); btn2.setText("DC".toString()); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { btnDC.setEnabled(false); Intent intent = new Intent(CategoryActivity.this, BeginTestActivity.class); Bundle b = new Bundle(); databaseHandler = new DatabaseHandler(btnDC.getContext()); b.putString("category", btn2.getText().toString()); if (databaseHandler.getScoreForCategory(btn2.getText().toString()) != null) { b.putString("best_score", databaseHandler.getScoreForCategory(btn2getText().toString()).getScore()); } else { b.putString("best_score", "0"); } intent.putExtras(b); startActivity(intent); overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right); } }); } @Override public void onBackPressed() { super.onBackPressed(); overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave); } @Override protected void onPause() { super.onPause(); } } 

Closed due to the fact that the question is too common for participants Streletz , aleksandr barakin , Denis , user194374, D-side 2 Sep '16 at 8:20 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Suppose you have a button, for example Button mStartLevelTwo . You can add the attribute android:enabled="false" in the XML markup of this button, then, by default, this button will be inaccessible.

    Further, when you consider it necessary to make this button available, simply execute mStartLevelTwo.setEnabled(true) .

    To get more specifics, try to make people around you understand what btn1 and btn2 do, for example ( this will be useful not only for others , but also for you). Name the objects meaningfully.

    • The problem is that I can’t count points from level 1 and write a method in which level 2 was unlocked by dialing a certain number of points in level 1! There are only 2 buttons, the first one starts level 1 (data is taken from the database), and the second one starts level 2 (data is taken from the database too) - 2Ra66it