У меня есть два переключателя и одно текстовое поле редактирования в диалоговом окне предупреждения.Как очистить другие поля от щелчка одного элемента управления
Например, если я выбрал одну кнопку радио, данные редактирования текста должны очистить и наоборот
Ниже мой код: Пожалуйста, посмотрите на это и помочь мне
public class MainActivity extends Activity {
Button press;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
press =(Button)findViewById(R.id.press);
press.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertFormElements();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/*
* Show AlertDialog with some form elements.
*/
public void alertFormElements() {
/*
* Inflate the XML view. activity_main is in
* res/layout/form_elements.xml
*/
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View formElementsView = inflater.inflate(R.layout.form_elements,
null, false);
// You have to list down your form elements
final RadioGroup genderRadioGroup = (RadioGroup) formElementsView
.findViewById(R.id.genderRadioGroup);
final EditText nameEditText = (EditText) formElementsView
.findViewById(R.id.nameEditText);
// the alert dialog
new AlertDialog.Builder(MainActivity.this).setView(formElementsView)
.setTitle("Form Elements")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String toastString = "";
/*
* Getting the value of selected RadioButton.
*/
// get selected radio button from radioGroup
int selectedId = genderRadioGroup
.getCheckedRadioButtonId();
// find the radiobutton by returned id
RadioButton selectedRadioButton = (RadioButton) formElementsView
.findViewById(selectedId);
toastString += "Selected radio button is: "
+ selectedRadioButton.getText() + "!\n";
/*
* Getting the value of an EditText.
*/
toastString += "Name is: " + nameEditText.getText()
+ "!\n";
Toast.makeText(getApplicationContext(), "Item Clicked:" + toastString, Toast.LENGTH_SHORT).show();
dialog.cancel();
}
}).show();
}
}
Как написать условие .. – Razul
В каком состоянии? Пожалуйста, будьте как можно более конкретными, задавая вопросы. –