安卓开发问题。activity跳转后新activity是空白,但我明明有定义的
MainActivity定义如下:publicclassMainActivityextendsActionBarActivity{Buttonbn1;@Overridep...
MainActivity定义如下:
public class MainActivity extends ActionBarActivity {
Button bn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bn1 = (Button)this.findViewById(R.id.bn1);
bn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,bn1.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
bn1.JAVA定义如下:
package com.example.activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class bn1 extends ActionBarActivity{
public void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bn1);
}
}
本来应该是按按钮会显示哈哈,做个测试,但是虚拟机运行后全发现什么都没有。
我把MainActivity中的Import去掉了,百度说超过字数限制~ 展开
public class MainActivity extends ActionBarActivity {
Button bn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bn1 = (Button)this.findViewById(R.id.bn1);
bn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,bn1.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
bn1.JAVA定义如下:
package com.example.activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class bn1 extends ActionBarActivity{
public void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bn1);
}
}
本来应该是按按钮会显示哈哈,做个测试,但是虚拟机运行后全发现什么都没有。
我把MainActivity中的Import去掉了,百度说超过字数限制~ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询