求解决bug,初学android,
packagecom.example.say_hello;importandroid.os.Bundle;importandroid.app.Activity;impor...
package com.example.say_hello;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData.Item;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0,1,0, "say hello");
menu.add(0,2,0, "exit");
return true;
}
public boolean onOptionsItemSelected(Item item)
{
super.onOptionsItemSelected((MenuItem) item);
int id = item.getId();
switch(id)
{
case 1:AlertDialog.show(this,getString(R.string.app_name),getString(R.string.msg_dialog),
getString(R.string.ok_dialog),true);
break;
case 2:
finish();
break;
}
}
} 展开
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData.Item;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0,1,0, "say hello");
menu.add(0,2,0, "exit");
return true;
}
public boolean onOptionsItemSelected(Item item)
{
super.onOptionsItemSelected((MenuItem) item);
int id = item.getId();
switch(id)
{
case 1:AlertDialog.show(this,getString(R.string.app_name),getString(R.string.msg_dialog),
getString(R.string.ok_dialog),true);
break;
case 2:
finish();
break;
}
}
} 展开
1个回答
展开全部
/**bug已经修复,请测试看看*/
package com.example.say_hello;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0,1,0, "say hello"芹锋卖基高);
menu.add(0,2,0, "exit");
return true;
}
@Override //重写onOptionsItemSelected方法,参数为MenuItem类型,itemId获取是item.getItemId()方法。
public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
int id = item.getItemId();
switch(id){
case 1:
//这里没有AlertDialog.show()方法。弹出一个对话框应该这样写。
new AlertDialog.Builder(this).setTitle("标题"嫌逗).setMessage("修复bug").show();
break;
case 2:
finish();
break;
}
return true;
}
}
package com.example.say_hello;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0,1,0, "say hello"芹锋卖基高);
menu.add(0,2,0, "exit");
return true;
}
@Override //重写onOptionsItemSelected方法,参数为MenuItem类型,itemId获取是item.getItemId()方法。
public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
int id = item.getItemId();
switch(id){
case 1:
//这里没有AlertDialog.show()方法。弹出一个对话框应该这样写。
new AlertDialog.Builder(this).setTitle("标题"嫌逗).setMessage("修复bug").show();
break;
case 2:
finish();
break;
}
return true;
}
}
追问
谢谢你啊,bug没有了,不过为什么就显示一个hello_world
追答
系统默认是Hello World.把它的默认页面修改成自己的,具体显示什么,需要在相应的layout 样式资源文件中(.xml)配置即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询