1
두 개의 버튼을 가져 오는 인플레이터 메뉴를 만들었습니다. 하나는 클릭 할 수있는 항목 목록에 대한 링크로, 클릭하면 메뉴가 닫히고 기본 메뉴로 돌아갑니다. 화면보기. 그러나 다른 버튼은 작동하는 라디오 버튼 목록을 가져 오지만이 메뉴를 닫으려면 리턴 키를 눌러야합니다. 옵션 중 하나를 선택하면 자동으로 닫히고 싶습니다.옵션을 선택한 후 인플레이터 메뉴를 닫으려면 어떻게해야합니까?
어떻게하면 좋을지에 대한 제안은 도움을 주셔서 감사드립니다.
@Override
public boolean onCreateOptionsMenu(Menu menu) { //creates the menu options that appear when the menu button is pressed
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mainmenu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) { // assigns one button in the menu to display Rhythm and then further options
final CharSequence[] Rhythms = {"Sinus Rhythm", "Atrial Fibulation", "Atrial Flutter", "Junctional Rhythm", "SVT", "Ventricular Tachycardia"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Interpretation of ECG waveform");
builder.setItems(Rhythms, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int Rhythm) {
Toast.makeText(getApplicationContext(), Rhythms[Rhythm], Toast.LENGTH_SHORT).show(); // add a save function here to utilise the onclick function
} // saved file should match the ecg file name and also be loaded when app is started
});
final CharSequence[] annotations = {"A", "B", "B-","C", "C-", "D", "F"}; // assigns a new button with the annotation options
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setTitle("Evaluate ECG quality");
builder1.setSingleChoiceItems(annotations, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), annotations[item], Toast.LENGTH_SHORT).show(); // again add a save function here, this should be able to override the
// annotation coding written by Daniel.
}
});
setCancelable(true);
switch (item.getItemId()) {
case R.id.annotatebutton: // when annotation button is click display annotation options
builder1.show();
return true;
case R.id.rhythmbutton: // when rhythm button is clicked display rhythm options
builder.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}