java - 如何使我的带有 queue.poll() 值的变量可供其他活动访问
问题描述
我有一个 Java 类项目,我正在使用 android studio 进行编码。
该项目是石头剪刀布。
基本上,我制作了一个包含敌人名称的队列。
我q.poll()
给了他们一个变量,名称为firstenemy
,secondenemy
和thirdenemy
。
在第一个游戏中,我想将我的文本视图设置为第一个敌人。然后,在用户获胜后,它将把用户带到下一个布局相似但敌人名称不同的活动。
在这里,我想使用secondenemy
第一个游戏活动中的变量设置 textview 名称。
我怎样才能做到这一点 ?或者,有没有办法将其转换q.poll()
为字符串?
很抱歉问(也许)这样一个菜鸟问题。
这是我在第一个游戏活动中的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gameplay);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Queue<String> q = new LinkedList<>();
Intent intent = getIntent();
String text = intent.getStringExtra(Page2Activity.EXTRA_TEXT);
nama = findViewById(R.id.name);
nama.setText(text);
q.add("Jackson");
q.add("Diamante");
q.add("Borsalino");
String firstenemy = q.poll();
String secondenemy = q.poll();
String thirdenemy = q.poll();
TextView textView4 = findViewById(R.id.textView4);
textView4.setText(firstenemy);
winners = findViewById(R.id.winners);
userresult = findViewById(R.id.userresult);
enemyresult = findViewById(R.id.enemyresult);
userresult.setText(text);
enemyresult.setText(firstenemy);
userresult2 = findViewById(R.id.userresult2);
enemyresult2 = findViewById(R.id.enemyresult2);
rand = new Random();
}
解决方案
推荐阅读
- node.js - 本地主机的 Node.js https 服务器
- opengl - GLSL 字节顺序宏
- javascript - “CORS 问题 - 403 禁止”在 javascript 中使用 xmlhttprequest
- javascript - JavaScript 函数不能按照 JSON 响应工作
- javascript - 为什么 regExp 在 diff senarios 中有 diff 结果?
- in-app-purchase - 如何在沙盒环境中测试 `DID_FAIL_TO_RENEW` 、 `CANCEL` 和任何其他事件
- android - 如何在android中使用cordova在后台打包和执行二进制文件?
- vue.js - vue在一个组件中打开一个组件
- jquery - 匹配 JQuery 中的确切字符串
- javascript - 如何使一组三角形相互碰撞?