lundi 28 septembre 2015

How to make random string replace textview?

I have an activity with 3 edittexts and a button. I have a second activity with 2 textviews.

When button is clicked i want two random edittexts values from activity1 to replace the text on textviews on activity2.

I managed to do that, but not randomly. How can I make it random?

Here is the first activity.

final EditText et  = (EditText) findViewById(R.id.editText);
        final EditText et1 = (EditText) findViewById(R.id.editText2);
        final EditText et2 = (EditText) findViewById(R.id.editText3);
        Button btn = (Button) findViewById(R.id.button);

        btn.setOnClickListener(new View.OnClickListener() {

            public void onClick (View v){
                Intent i = new Intent(MainActivity.this, postavke.class);
                i.putExtra("prvi", et.getText().toString());
                i.putExtra("drugi", et1.getText().toString());
                i.putExtra("treci", et2.getText().toString());
                startActivity(i);
            }
        });
    }

Here is the second activity.

   TextView tv = (TextView) findViewById(R.id.asdf);
    tv.setText(getIntent().getExtras().getString("prvi"));

TextView dr = (TextView) findViewById(R.id.asdg);
dr.setText(getIntent().getExtras().getString("drugi"));




Aucun commentaire:

Enregistrer un commentaire