gpt4 book ai didi

java - Android 字符串为空

转载 作者:行者123 更新时间:2023-12-01 18:14:11 24 4
gpt4 key购买 nike

我的代码有问题

if ((equip != null) && equip.trim().equals("")){
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_layout_equip);

我的其他是

final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_layout);

因此,如果我的字符串为空或为空,我将使用此对话框dialog.setContentView(R.layout.dialog_layout);否则我用这个dialog.setContentView(R.layout.dialog_layout_equip);

我的 logcat 为我提供了此代码的输出

String equip = reserveComp.getString(TAG_EQUIP);
Log.d("Equip", equip);

D/Equip:投影仪,所以它打开

dialog.setContentView(R.layout.dialog_layout);

但是当我有这个输出时D/Equip:null打开一样

那怎么了?

更新

这是我的完整 block 代码

JSONObject reserveComp = reqFeitasDetail.getJSONObject(0);
String equip = reserveComp.getString(TAG_EQUIP);
Log.d("Equip", equip);
if ((equip == null) || equip.trim().equals("")){
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_layout);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
Button img = (Button) dialog.findViewById(R.id.close_button);
TextView data = (TextView) dialog.findViewById(R.id.data);
TextView sala = (TextView) dialog.findViewById(R.id.sala);
TextView hora = (TextView) dialog.findViewById(R.id.hora_inicial);
TextView fim = (TextView) dialog.findViewById(R.id.hora_final);
data.setText(reserveComp.getString(TAG_DATA));
sala.setText(reserveComp.getString(TAG_NOME));
hora.setText(reserveComp.getString(TAG_TEMPO));
fim.setText(reserveComp.getString(TAG_TEMPOFIM));
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
} else {
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_layout_equip);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
Button img = (Button) dialog.findViewById(R.id.close_button);
TextView data = (TextView) dialog.findViewById(R.id.data);
TextView sala = (TextView) dialog.findViewById(R.id.sala);
TextView equipamento = (TextView) dialog.findViewById(R.id.equip);
TextView hora = (TextView) dialog.findViewById(R.id.hora_inicial);
TextView fim = (TextView) dialog.findViewById(R.id.hora_final);
data.setText(reserveComp.getString(TAG_DATA));
sala.setText(reserveComp.getString(TAG_NOME));
equipamento.setText(reserveComp.getString(TAG_EQUIP));
hora.setText(reserveComp.getString(TAG_TEMPO));
fim.setText(reserveComp.getString(TAG_TEMPOFIM));
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}

我有这个 logcat 输出

D/Reserva Sala completa﹕ {"tag":"reqEquipFull","success":1,"error":0,"reqEquipFull":[{"data":"2015-06-12","sala":"21","inicio":"14:05:00","fim":"15:45:00","nome":null}]}

D/装备: null

我的对话框仍然有同样的问题,所有(空和非空)打开此对话框

dialog.setContentView(R.layout.dialog_layout_equip);

最佳答案

要检查字符串是否为空为空,if block 内的条件应为

if ((equip == null) || equip.trim().equals("")){...}

如果您想执行以下操作,还应该切换 if-else 语句中的代码块..

So if my string is null or empty i use this dialog dialog.setContentView(R.layout.dialog_layout); Otherwise i use this one dialog.setContentView(R.layout.dialog_layout_equip);

if ((equip == null) || equip.trim().equals("")){
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_layout);
}
else {
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_layout_equip);
}

关于java - Android 字符串为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30713591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com