我试图加载一个XML活动,当用户点击下面的链接按钮时。如何从对话框中启动xml活动?
有人可以协助吗?我不知道怎么做(和它的驾驶我坚果!)
所有我想要做的是,当用户点击“链接”让他们派人过来AppActivity2.java/main2.xml
package com.mkyong.android;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AppActivity extends Activity {
final Context context = this;
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.button1);
// add button listener
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Settings Menu");
// set dialog message
alertDialogBuilder
.setMessage("Link or Delete?")
.setCancelable(false)
.setPositiveButton("Link",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
AppActivity.this.finish();
}
})
.setNegativeButton("Delete",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
}
}
你是知道的意图?它从一个页面转到另一个页面。 – Shachi 2013-03-02 07:29:45
请参考Android意图以及如何在按钮点击时触发它们,您应该在发布您的问题之前进行调查 – 2013-03-02 07:32:00
我不是,但我只是通过http://developer.android.com/reference阅读了一下/android/content/Intent.html 但是我仍然不确定我可以添加到这个切换到另一个页面的代码行。 – 2013-03-02 07:35:03