我是新来的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:
developer.android/guide/components/fragments.html
www.vogella/articles/Android/article。 HTML#fragments_tutorial
这两个非常有用的,但是当我试图执行有问题。
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.
更多推荐
启动一个新的活动
发布评论