2010-05-19 3 views
2

У меня есть два Activity s, названный App и Gallery.Как открыть активность в кнопке onClick()?

App содержит интерфейсные кнопки и функциональные возможности, Gallery перечисляет изображения на SD-карте.

Я хочу открыть Gallery в onClick() внутри 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)) { 


    } 

} 
} 
+0

Пожалуйста, форматировать Ваш код правильно, и, пожалуйста, переформулируйте «как я могу вызвать java-файл ...» – aioobe

+0

Возможный дубликат [Как начать новую активность при нажатии кнопки] (http : //stackoverflow.com/questions/4186021/how-to-start-new-activity-on-button-click) – Sufian

ответ

2

если ваш Gallery.java является деятельность, вы можете запустить его по телефону startActivity(new Intent(this, Gallery.class));

0

Используйте Намерение

Intent intent = new Intent(this,Gallery.class); 
intent.putExtra(<key>,<value>); 
startActivity(intent); 
Смежные вопросы