本文介绍了如何在按钮的onClick()中打开活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Activity,分别是AppGallery.

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

App contains frontend buttons and functionalities, Gallery lists the images in the sd card.

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

I want to open Gallery in onClick() inside App.

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是活动,则可以通过调用startActivity(new Intent(this, Gallery.class));

if your Gallery.java is an activity you could start it by calling startActivity(new Intent(this, Gallery.class));

这篇关于如何在按钮的onClick()中打开活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 06:59