Add an options menu with item “About” and a customized dialog (not Alert Dialog) for…
- User
Add an options menu with item “About” and a customized dialog (not Alert Dialog) for “About” into car rental app.
Please do so with the following android studio code in Java:
public class MainActivity extends AppCompatActivity {
@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 an options menu with the item "About" and a customized dialog for "About", you can follow these steps:
- Create a new menu file called "menu_main.xml" in the "res/menu" folder. Add the following code to the menu file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_about" android:title="About" /> </menu>- Modify your MainActivity class to implement the "Toolbar.OnMenuItemClickListener" interface. You can do this by changing the class declaration line to:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.