This is for Android Studio in Java Code. • Design an app to store contacts information.…
- User
This is for Android Studio in Java Code. • Design an app to store contacts information. • Main screen shows all names saved in database as a list. • One icon allows the customer to add a new contact to the database. When this icon clicked, a blank EditContact screen is displayed. • Main screen also allows searching by entering key information into the searching box. The list of contact information will be updated when information is entered into the searching box. • Use SearchView to let customer enter key information into. • Use SearchView.setOnQueryTextListener to listen the text change in search box. • By clicking an item in the contact list, another screen will display the detail information of the selected contact. • The Detail screen will display the detail information of the selected contact. Two buttons/icons at the bottom of the screen allows customer to choose to save or delete this contact information. • When save button/icon is clicked, this contact will be added/updated and back to Main screen. • When delete button/icon is clicked, this contact will be deleted and back to Main screen.
This app is ONLY meant to save names and phone numbers
- Assistant
- User
what about ContactDetailActivity.class?
- Assistant
Here's an example implementation for ContactDetailActivity class:
public class ContactDetailActivity extends AppCompatActivity { private TextView nameTextView; private TextView phoneTextView; private Button saveButton; private Button deleteButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_contact_detail); nameTextView = findViewById(R.id.nameTextView); phoneTextView = findViewById(R.id.phoneTextView); saveButton = findViewById(R.id.saveButton); deleteButton = findViewById(R.id.deleteButton); // Get contact details from intent String name = getIntent().getStringExtra("name"); String phone = getIntent().getStringExtra("phone"); nameTextView.setText(name); phoneTextView.setText(phone); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(ContactDetailActivity.this, "Contact saved", Toast.LENGTH_SHORT).show(); // Add the logic to save/update the contact information finish(); } }); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(ContactDetailActivity.this, "Contact deleted", Toast.LENGTH_SHORT).show(); // Add the logic to delete the contact information finish(); } }); } } - User
revise MainActivity.java to include a button to add contacts
- Assistant
- User
and next is AddContactActivity.class
- Assistant
Certainly! Here is an example implementation for AddContactActivity class:
public class AddContactActivity extends AppCompatActivity { private EditText nameEditText; private EditText phoneEditText; private Button addButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_contact); nameEditText = findViewById(R.id.nameEditText); phoneEditText = findViewById(R.id.phoneEditText); addButton = findViewById(R.id.addButton); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = nameEditText.getText().toString(); String phone = phoneEditText.getText().toString(); if (!name.isEmpty() && !phone.isEmpty()) { Intent resultIntent = new Intent(); resultIntent.putExtra("name", name); resultIntent.putExtra("phone", phone); setResult(RESULT_OK, resultIntent); finish(); } else { Toast.makeText(AddContactActivity.this, "Please enter name and phone number", Toast.LENGTH_SHORT).show(); } } }); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.