最有效的方法使用位置打开的.java [英] Most efficient method to use position to open a .java

查看:107
本文介绍了最有效的方法使用位置打开的.java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,格式化错误 - 你怎么使用的位置,一旦你拥有了它(或其他变量为此事),激活文件或其他任务?比如我想使用位置1开启screen1.java和位置2开启screen2.java。我可以使用if / else语句,但在一条线,我可以做到这一点,而不是很多?如果我有100个不同的屏幕和一个if then语句将是愚蠢的。下面是我作为一个(不正确)的例子。你能不能帮我纠正吗?

Sorry for the formating errors - How do you use position once you have it (or another variable for that matter) to activate a file or other task? For example I want to use position 1 to open screen1.java and position 2 to open screen2.java. I could use if/else statements but can I do it in one line rather than many? If I had 100 different screens then an if then statement would be silly. Here is what I have as an (incorrect) example. Can you help me correct it?

public void onItemClick(AdapterView<?> parent, View v,
int position, long id){
//opens relevant game window
Intent intent = new Intent(context, "game"+(position)+"mainscreen"+".class");
startActivity(intent);
} 
});
}

总结: - 而不是使用 game1mainscreen.class 我想使用类似游戏+(位置)+mainscreen+级的

TO SUMMARIZE:- instead of using game1mainscreen.class I want to use something like "game"+(position)+"mainscreen"+".class"

推荐答案

您可以定义意图过滤器让您在AndroidManifest.xml文件的活动如下:

You can define intent filter for your activities in AndroidManifest.xml file as follows

<activity
  android:name=".Game1MainScreen"
  android:label="@string/app_name"
    <intent-filter>
      <action android:name="com.mygame.game1mainscreen" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

以下code和使用后,开始你的游戏活动。

and after that use following code to start your game activity

Intent intent = new Intent("com.mygame.game"+(position)+"mainscreen");
startActivity(intent);

这篇关于最有效的方法使用位置打开的.java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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