如何使用变量,而在意向呼吁新的活动? [英] how to use variable while calling new activity in intent?

查看:73
本文介绍了如何使用变量,而在意向呼吁新的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code调用新的活动

i have following code to call new activity

现在我想用变量来调用新的活动

now i want to use variable to call new activity

字符串VAR1,VAR2,VAR3; VAR1 =登陆; VAR2 =注册; VAR3 =多;

String var1,var2,var3; var1="Login"; var2="Signup"; var3="more";

Intent i; 
i = new Intent(Favorites.this, Login.class);  --> login.class with var 
startActivity(i); 

任何一个可以指导我如何实现这一目标???

can any one guide me how to achieve this???

推荐答案

您不能传递一个字符串作为参数它必须是一个活动。

You cant pass a String in as the parameter it has to be an Activity.

使用if或switch语句的不同选择,你必须之间切换。

Use an if or switch statement to switch between the different selections you have.

这样的事情,也许......

Something like this maybe....

Intent i; 
switch(var)
case:Login
i = new Intent(Favorites.this, Login.class); 
break; 
case:Signup
i = new Intent(Favorites.this, Signup.class);
break;   
case:More
i = new Intent(Favorites.this, More.class);
break; 


startActivity(i); 

这篇关于如何使用变量,而在意向呼吁新的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆