2
2
2Ra66it2016-08-30 22:33:26
css
2Ra66it, 2016-08-30 22:33:26

How to block a button and make it available when the user reaches a certain number of points?

In general, there are buttons that launch a certain level, how to make it so that level 2 (2 button) is unlocked when the user scores a certain number of points on level 1. Give me a hint, I'm just new to android development!

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.setEnabled(false);
        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();

    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
HamSter, 2016-06-23
@afishr

codepen
codepen

O
one pavel, 2016-08-30
@onepavel

why are you using this line btn2.setEnabled(false); ?

R
Rou1997, 2016-09-01
@Rou1997

Hey!
Obviously, you need to "throw out" the user from the first level back to the CategoryActivity, while passing information about passing the first level to it, you can act "stupidly", that is, just open it also through the Intent, but you should make sure that the old Activity instances were deleted from the RAM and it was impossible to return to them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question