Android 视图随点击而变化
我需要一些简单的东西,能够像在 iPhone 中一样在我的应用程序中切换视图, 例如,我使用按钮加载第一个屏幕,单击此按钮并转到下一个屏幕,并且可以返回(我们都在 iPhone UI 中看到“后退”按钮)。 我一直在尝试执行 startActivity(this,MySecondScreen.class) 但它崩溃了。
public class mainClass extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void login_Click(View v) {
// Perform action on click
try{
Intent i = new Intent(this, MainMenuTabs.class);
startActivity(i);
}
catch(Exception ex)
{
Log.e("main",ex.toString());
}
}
我的第二个
类是 TabActivity 扩展程序 公共类 pissedoff 扩展了 Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenuview);
}
public void login_Click(View v) {
// Perform action on click
try{
Intent i = new Intent(this, MainMenuTabs.class);
startActivity(i);
}
catch(Exception ex)
{
Log.e("main",ex.toString());
}
}
}
I need something simple, an ability to switch views in my app like I do in iPhone,
for example I load first screen with button, click on this button and go next screen with an ability to go back ( We all see Back button in the iPhone UI ).
I've been trying to do startActivity(this,MySecondScreen.class) but it crashes.
public class mainClass extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void login_Click(View v) {
// Perform action on click
try{
Intent i = new Intent(this, MainMenuTabs.class);
startActivity(i);
}
catch(Exception ex)
{
Log.e("main",ex.toString());
}
}
}
and my second class is this which is a TabActivity extender
public class pissedoff extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenuview);
}
public void login_Click(View v) {
// Perform action on click
try{
Intent i = new Intent(this, MainMenuTabs.class);
startActivity(i);
}
catch(Exception ex)
{
Log.e("main",ex.toString());
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它可能会崩溃,因为在你的 android 清单文件中还必须声明这样的活动:
或者使用内置的图形东西。 (Android 清单 -> 应用程序 -> 应用程序节点 -> 添加 -> Activity)
It might crash because in your android manifest file also have to declare activity like that:
Or use the built in grahpical thing. (Android manifest -> Application -> Application Nodes -> Add -> Activity)
在您的 XML 中,为每个视图创建一个文件(使其更易于使用),然后在您的 main:
在您的 java 代码中:
当您想使用下一个视图时,请使用
vf.showNext();
In Your XML, create a file for each view (makes it easier to work with), then in your main:
in your java code:
when you want to use the next view use
vf.showNext();
1.这就是您的主活动的外观。在布局中添加按钮。
这就是您的下一个 Activity 的外观。使用 onBackpressed 方法。
3.希望有帮助。
1.This is how your Main Activity should look.Add button in the layout.
This is how your Next Activity should look.Use onBackpressed Method.
3.Hope it helps.