我如何调用另一个Java类上点击一个java文件? [英] how do i call a java file on click in another java class?
问题描述
我有两个文件
App.java
Gallery.java
Gallery.java
应用程序。 java的包含前端的按钮和功能 Gallery.java列出imagesin SD卡
App. java contains frontend buttons and functionalities Gallery.java lists the imagesin the sd card
我要打电话Gallery.java在点击事件中app.java
i want to call Gallery.java in click event in app.java
App.java
包gallery.display;
package gallery.display;
进口android.app.Activity; 进口android.os.Bundle; 进口android.view.View.OnClickListener; 进口android.view.View; 进口android.widget.Button; 进口android.widget.Toast; 进口android.app.AlertDialog; 进口android.content.DialogInterface; 进口android.app.ProgressDialog;
import android.app.Activity; import android.os.Bundle; import android.view.View.OnClickListener; import android.view.View; import android.widget.Button; import android.widget.Toast; import android.app.AlertDialog; import android.content.DialogInterface; import android.app.ProgressDialog;
公共类应用扩展活动实现OnClickListener {
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(新意图(这一点,Gallery.class))启动;
if your Gallery.java is an activity you could start it by calling startActivity(new Intent(this, Gallery.class));
这篇关于我如何调用另一个Java类上点击一个java文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!