앱이 시작되지만 Select_Players 버튼을 클릭하면 대화 상자가 내 기기에 표시되지 않습니다. 다음은 코드입니다 : 나는 대화 방법은 대화가 반환 볼Android setOnClick이 작동하지 않음/Dialogbox가 표시되지 않음
public class MainActivity extends Activity {
private Button selectPlayers;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
super.onStart(); //customize
super.onResume(); //customize
selectPlayers = (Button) findViewById(R.id.add_players);
selectPlayers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launch dialogbox on click
onCreateDialog(savedInstanceState);
}
});
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
@SuppressWarnings("rawtypes")
final ArrayList mSelectedItems = new ArrayList(); // Where we track the selected items
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Set the dialog title
builder.setTitle(R.string.select_players)
// Specify the list array, the items to be selected by default (null for none),
// and the listener through which to receive callbacks when items are selected
.setMultiChoiceItems(R.array.players_name, null,
new DialogInterface.OnMultiChoiceClickListener() {
@SuppressWarnings("unchecked")
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the selected items
mSelectedItems.add(which);
} else if (mSelectedItems.contains(which)) {
// Else, if the item is already in the array, remove it
mSelectedItems.remove(Integer.valueOf(which));
}
}
})
// Set the action buttons
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//CODE TO CLOSE DIALOGBOX AND START FORGE
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//CODE TO JUST CLOSE DIALOGBOX
}
});
return builder.create();
}
}
그러나 나는 그것이 온 클릭의 결과로 나타나게하는 방법을 잘 모르겠어요? (참고로 Android 개발자 웹 사이트에서 Dialog 메서드를 사용했습니다.)
고마워요! 당신은 당신의 onclick이 같은 일을 구축 할 수 있도록
그냥 대화 상자를 표시하는 데 효과적입니다. 감사합니다. – newenthusiast