Is there an easy way to have a button pressed automatically within 1 second of opening that window/activity in my android app.
At the moment I need to press the 'bVoice' button to start voice recognition using b.setOnClickListener(this)
. I wish to rather than pressing the button to automatically be pressed within 1 second of opening that particular window/activity.
Is there a simple way of implmenting this? Below is part of my code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
ListView lv;
static final int check = 1111;
Button b;
EditText a;
Button c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lvVoiceReturn);
a = (EditText) findViewById(R.id.TFusername);
b = (Button) findViewById(R.id.bVoice);
c = (Button)findViewById(R.id.Blogin);
b.setOnClickListener(this);
}
public void onButtonClick(View v) {
if (v.getId() == R.id.Blogin) {
String str = a.getText().toString();
//Go to the relevant page if any part of the phrase or word entered in the 'EditText' field contains 'next' which is not case sensitive
if (str.toLowerCase().contains("next")) {
Intent userintent = new Intent(MainActivity.this, Display_1.class);
startActivity(userintent);
} else if (str.toLowerCase().contains("heart")) {
Intent userintent = new Intent(MainActivity.this, Display_2.class);
startActivity(userintent);
} else {
Toast.makeText(getApplicationContext(), "Incorrect Information", Toast.LENGTH_SHORT).show();
}
}
}