我的问题是当我点击程序员打开twitter时!
{参见主java的结尾;这是我的菜单}
当我在模拟器上单击twitter时,它会打开程序员,反之亦然。
问题出在哪里?
main java
package com.rum.city;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class myMenu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bt_about = (Button) findViewById(R.id.about);
bt_about.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(myMenu.this, about.class));
}
});
Button bt_blocks = (Button) findViewById(R.id.blocks);
bt_blocks.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(myMenu.this, blocks.class));
}
});
Button bt_hosay = (Button) findViewById(R.id.hosay);
bt_hosay.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(myMenu.this, hosay.class));
}
});
Button bt_stati = (Button) findViewById(R.id.stati);
bt_stati.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(myMenu.this, stati.class));
}
});
}
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater awesome = getMenuInflater();
awesome.inflate(R.menu.main_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.menunews:
String url = "http://j.mp/rumnw";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
return true;
case R.id.menutwitter:
String rb6 = "https://twitter.com/#!/Rum_City";
Intent r = new Intent(Intent.ACTION_VIEW);
r.setData(Uri.parse(rb6));
startActivity(r);
return true;
case R.id.menuhwl:
startActivity(new Intent("com.rum.city.HWL"));
return true;
}
return false;
}
}
menu xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
/>
<item
android:id="@+id/menunews"
android:alphabeticShortcut="s"
android:title="news"
/>
<item
android:id="@+id/menutwitter"
android:alphabeticShortcut="t"
android:title="twitter"
/>
<item
android:id="@+id/menuhwl"
android:title="programmer"
android:alphabeticShortcut="a">
</item>
答案 0 :(得分:7)
您最近是否更改了ID?有时IDE会混淆并混淆ID。 解决这个问题的方法是清理项目&amp;重建。
答案 1 :(得分:0)
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.menunews:
String url = "http://j.mp/rumnw";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
break;
case R.id.menutwitter:
String rb6 = "https://twitter.com/#!/Rum_City";
Intent r = new Intent(Intent.ACTION_VIEW);
r.setData(Uri.parse(rb6));
startActivity(r);
break;
case R.id.menuhwl:
startActivity(new Intent("com.rum.city.HWL"));
break;
}
}
return true;
}