问题描述
我是新来的Java编程和Android ...这里是我的问题,同样不知道如果我提供的信息就足够了。
我想要做的就是创建一个简单的两活动的应用程序....
所以我有主要活动和用户点击一个按钮和一个新的活动推出了设置一个新的布局。
i'm new to programming in Java and android... Here is my question, again not sure if the information I provide is sufficient.What I'm trying to do is create a simple two activity app....So i have the main activity and a user clicks a button and a new activity is launched that sets a new layout.
我已经看了两个以下网站:
I've looked at the two following websites:
这两个非常有用的,但是当我试图执行有问题。
Both very useful but when I tried to implement had issues.
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button buttonLoadProfile = (Button) findViewById(R.id.buttonLoadProfile);
buttonLoadProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent profileIntent = new Intent();
profileIntent.setClass(getActivity(),LoadProfile.class);
// setContentView(R.layout.profile_layout);
}
});
}
我得到的错误是的方法getActivity()是未定义的类型新View.OnClickListener(){}
The error I get is "The method getActivity() is undefined for the type new View.OnClickListener(){}"
推荐答案
使用
Intent profileIntent = new Intent( MainActivity.this, LoadProfile.class );
startActivity(profileIntent);
这会从内部解决封闭类。
This will resolve the enclosing class from the inner.
这篇关于启动一个新的活动 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!