gpt4 book ai didi

android - 如何在按钮的 onClick() 中打开 Activity ?

转载 作者:行者123 更新时间:2023-11-29 00:50:45 24 4
gpt4 key购买 nike

我有两个 Activity,名为 AppGallery

App 包含前端按钮和功能,Gallery 列出 sd 卡中的图像。

我想在 App 的 onClick() 中打开 Gallery

App.java

public class App extends Activity implements OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// set a click listener on the yesno button
Button Delete = (Button) findViewById(R.id.Delete);
Delete.setOnClickListener(this);

// set a click listener on the Upload button
Button Upload = (Button) findViewById(R.id.Upload);
Upload.setOnClickListener(this);

Button Listvideo = (Button) findViewById(R.id.Listvideo);
Listvideo.setOnClickListener(this);


}

public void onClick(View view) {
// which button is clicked?

// the Toast button


// the delete button is clicked
if (view == findViewById(R.id.Delete)) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

// set the message to display
alertbox.setMessage("Do u want to Delete!");

// set a positive/yes button and create a listener
alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "'Yes' button clicked", Toast.LENGTH_SHORT).show();
}
});

// set a negative/no button and create a listener
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {

// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "'No' button clicked", Toast.LENGTH_SHORT).show();
}
});

// display box
alertbox.show();
}

// the delete button is clicked
// the delete button is clicked
if (view == findViewById(R.id.Upload)) {

ProgressDialog dialog = new ProgressDialog(this);

// make the progress bar cancelable
dialog.setCancelable(true);

// set a message text
dialog.setMessage("Uploading the video...");

// show it
dialog.show();

}



if (view == findViewById(R.id.Listvideo)) {


}

}
}

最佳答案

如果您的 Gallery.java 是一个 Activity ,您可以通过调用 startActivity(new Intent(this, Gallery.class));

来启动它

关于android - 如何在按钮的 onClick() 中打开 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2865238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com