当单击菜单中的按钮时,它会打开xml文件

时间:2013-08-24 03:51:12

标签: eclipse

我正在尝试在我的应用中制作菜单。当我点击我发出的名为aboutUs的菜单按钮时,它应该打开一个XML文件来解释这个应用程序的内容。除非我运行应用程序并单击菜单按钮,应用程序才会强行关闭。继承我的mainactivity.java

 package com.JordanZimmittiDevelopers.BlazeCustomerService1;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;


 import com.JordanZimmittiDevelopers.BlazeCustomerService.R;

 public class MainActivity extends Activity implements OnClickListener {


 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 Button mail = (Button)findViewById(R.id.button1);
 mail.setOnClickListener(this);

}

@Override
public void onClick(View v) {
switch(v.getId())
{
       case R.id.button1:
          Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
          String[] recipients = new String[]{"jordanzimmitti@gmail.com", "",};
          emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
          emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "I Have A Question          Or Probelm:");
          emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My question or problem is:");
          emailIntent.setType("text/plain");
          startActivity(Intent.createChooser(emailIntent, "Click Your Defult E-mail To Send Your Message:"));
          finish();
      break;

   }
}



Override
 public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;

}

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.aboutUs:
    Intent i = new     Intent("com.JordanZimmittiDevelopers.BlazeCustomerService.AboutThisApp");
    startActivity(i);
}
return false;

} }

1 个答案:

答案 0 :(得分:0)

制作一个解释应用程序的活动,然后像这样重写onCreateOptionsMenu()

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    menu.add("Help").setIcon(R.drawable.HelpButton).setIntent(new Intent(this,HelpActivity.class));
    return super.onCreateOptionsMenu(menu);
}