This is my Code for the action bar i use.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.icon:
case R.id.Kur:
Intent Doviz = new Intent(MainActivity.this, MainActivity.class);
startActivity(Doviz);
finish();
return true;
case R.id.Hesap:
Intent Hesap = new Intent(MainActivity.this, Genel.class);
startActivity(Hesap);
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
I'm trying to make it so when someone clicks the icon at top ( which is in red circle at picture) it should do the same thing as my "Döviz Kuru" Button at action bar. I have 2 problems 1 is i cant seem to make same Intent work for 2 cases in the menu 2nd is R.id.İcon doesn't reach to icon. I also tried home and the name i give to that .png neither worked.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case android.R.id.home:
Intent Doviz = new Intent(MainActivity.this, MainActivity.class);
startActivity(Doviz);
finish();
return true;
case R.id.Kur:
Intent Doviz = new Intent(MainActivity.this, MainActivity.class);
startActivity(Doviz);
finish();
return true;
case R.id.Hesap:
Intent Hesap = new Intent(MainActivity.this, Genel.class);
startActivity(Hesap);
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
it gives an error abaut "Duplicate local variable Doviz". When i try to use the same Intent for 2 cases. the answer for the making 2 cases with same job is done like this.
case android.R.id.home:
case R.id.Kur:
Intent Doviz = new Intent(Genel.this, MainActivity.class);
startActivity(Doviz);
finish();
return true;