启动一个新的活动

编程入门 行业动态 更新时间:2024-10-26 04:28:11
本文介绍了启动一个新的活动 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新来的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.

更多推荐

启动一个新的活动

本文发布于:2023-11-06 21:47:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!