profile picture for android studio in Java: How do i add a menu with an "about" item. I…
- User
profile picture for android studio in Java: How do i add a menu with an "about" item. I have to implement it in the following code:
public class MainActivity extends AppCompatActivity {
code@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RadioButton sedan = findViewById(R.id.sedan); RadioButton suv = findViewById(R.id.suv); RadioButton mv = findViewById(R.id.mv); Button button = findViewById(R.id.next); SharedPreferences sharedPreferences = getSharedPreferences("car_types", Context.MODE_PRIVATE); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String selectedCarType = ""; if (sedan.isChecked()) { selectedCarType = "Sedan"; } else if (suv.isChecked()) { selectedCarType = "SUV"; } else if (mv.isChecked()) { selectedCarType = "Minivan"; } //save preferences SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("selected_car", selectedCarType); editor.apply(); Intent intent = new Intent(MainActivity.this, SavedPreference.class); startActivity(intent); } }); }}
- Assistant
To add a menu with an "about" item to your Android Studio project, you can follow these steps:
-
Create a new XML file for your menu. Right-click on the
resfolder in your Android project, select New > Android Resource File, and enter the File name asmenu_main(or any other desired name). Set the Resource type as "Menu" and click on the OK button. -
Open the newly created XML file
menu_main.xmland add the following code:
xml -