1
我最近切換到AndEngine使用此引擎稍微玩一下。在交換機之前,我已經實施了一個DialogFragment
這工作得很好。現在我想將這個DialogFragment
「移植」到AndEngine。因爲在AndEngine中沒有對FragmentActivity的支持(據我所知),我決定將我的代碼改爲簡單的Dialog
。 現在對話框打開很好,但是完全空白。只是一個帶有邊框的小黑色矩形。對話框打開空白
我看不出有什麼可能是我的代碼錯誤..可能你可以幫忙。
public class SimpleDialog extends Dialog {
final long number;
Context context;
public SimpleDialog (Context context, long number) {
super(context);
this.number = number;
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = ResourceManager.getInstance().activity.getLayoutInflater();
final View view = inflater.inflate(R.layout.logindialog, null);
final EditText editTextUserName = (EditText) view.findViewById(R.id.usernameToSubmit);
final EditText editTextPassword = (EditText) view.findViewById(R.id.passwordToSubmit);
TextView numberText = (TextView) view.findViewById(R.id.numberText);
highscoreText.setText("Number: " + Long.toString(number));
builder.setView(view)
.setNegativeButton(R.string.login_submit, null)
.setPositiveButton(R.string.login_abort, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});
final AlertDialog d = builder.create();
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button b = d.getButton(AlertDialog.BUTTON_NEGATIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
});
}
我這是怎麼打開對話框:
ResourceManager.getInstance().activity.runOnUiThread(new Runnable() {
@Override
public void run() {
new SimpleDialog(ResourceManager.getInstance().activity, number).show();
}
});
,如果你還需要我的佈局,請讓我知道。 非常感謝!
感謝您的解釋。它像一個魅力:) – puelo
@puelo沒問題:-) –
.setNegativeButton(R.string.login_submit,null) .setPositiveButton(R.string.login_abort,new DialogInterface.OnClickListener(){should be .setNegativeButton(R .string.login_abort,null) .setPositiveButton(R.string.login_submit,new DialogInterface.OnClickListener(){ – jazz