在我的Android应用程序中,我有两个activity
:
Player_List
Game_Launch
在第一个activity
中,我问player
的名称,如果所有名称都是空的,我们没有名字,但如果它们不是空的,我们会使用{{1} }。
当我添加4个玩家中的3个时,我players
和activity
。但是他添加了player
的玩家。
如何制作empty
?
Player_List:
check system
Game_Launch:
Intent i = new Intent(getApplicationContext(),Game_Launch.class);
i.putExtra("player1", player1.getText().toString());
i.putExtra("player2", player2.getText().toString());
i.putExtra("player3", player3.getText().toString());
i.putExtra("player4", player4.getText().toString());
startActivity(i);
当我使用此检查时,它不起作用。你能帮我解决我的问题吗?谢谢。
编辑:
Intent in = getIntent();
String player1= in.getExtras().getString("player1");
String player2= in.getExtras().getString("player2");
String player3= in.getExtras().getString("player3");
String player4= in.getExtras().getString("player4");
//Log.d();
if (!player1.equals("")) {
playerge= new String[] {"player2", "player3", "player4"};
}
else if (!player2.equals("")){
playerge= new String[] {"player1", "player3", "player4"};
}
else if (!player3.equals("")){
playerge= new String[] {"player1", "player2", "player4"};
}
else if (!player4.equals("")){
playerge= new String[] {"player1", "player2", "player3"};
}
else if (!player1.equals("") && (!player2.equals(""))){
playerge= new String[] {"player3", "player4"};
}
else if (!player3.equals("") && (!player4.equals(""))){
playerge= new String[] {"player1", "player2"};
}
My String 1已完成,2未完成,3已完成,4已完成,但我有P1吐司。
如何创建字符串:
With answerd i have tried :
Intent in = getIntent();
String player1 = in.getStringExtra("player1");
String player2 = in.getStringExtra("player2");
String player3 = in.getStringExtra("player3");
String player4 = in.getStringExtra("player4");
//Log.d();
if (!player1.equals("")) {
playerge= new String[] {"player2", "player3", "player4"};
Toast.makeText(getApplicationContext(), "p1", Toast.LENGTH_SHORT).show();
}
else if (!player2.equals("")) {
playerge= new String[] {"player1", "player3", "player4"};
Toast.makeText(getApplicationContext(), "p2", Toast.LENGTH_SHORT).show();
}
else if (!player3.equals("")) {
playerge= new String[] {"player1", "player2", "player4"};
Toast.makeText(getApplicationContext(), "p3", Toast.LENGTH_SHORT).show();
}
else if (!player4.equals("")) {
playerge= new String[] {"player1", "player3", "player2"};
Toast.makeText(getApplicationContext(), "p4", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "tout ok", Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:3)
您收到的数据不正确。当您编写如下数据时:
Intent i = new Intent(getApplicationContext(), Game_Launch.class);
i.putExtra("player1", player1.getText().toString());
你得到它:
Intent in = getIntent();
String player1= in.getStringExtra("player1");
现在你可以按原样进行比较。
答案 1 :(得分:0)
希望这有帮助。
if(player1.equalsIgnoreCase("") && (!TextUtil.isempty(player1)) )
获取数据如下:
Intent in = getIntent();
String player1= in.getStringExtra("player1");