androidstudio中的if语句有一个意外的结果,为什么



在我的可扩展列表视图中,我编写了(if(语句,如果子行中包含两个单词,则返回一个(对话框(。。

这是代码:

.......
childObjects.add(new ChildObject(cetamol + " " + syr + " 160 " + mg5ml
, cetamolDoseMini160));
..........

elv = findViewById(R.id.elv);
elv.setOnGroupExpandListener(onGroupExpandListenser);
MyExpandableAdapter adapter = new MyExpandableAdapter(this, getData());
elv.setAdapter(adapter);
elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
for (int i = 0; i < ((ViewGroup) v).getChildCount(); ++i) {
View nextChild = ((ViewGroup) v).getChildAt(i);
if (nextChild.getId() == R.id.txtChildName) {
String data = ((TextView) nextChild).getText().toString();
String paracetamol = getResources().getString(R.string.Paracetamol);

if (data.contains(paracetamol)|| data.contains("160")) {
AlertDialog.Builder builder = new AlertDialog.Builder(Analgesics.this);
builder.setTitle(" Paracetamol 160:");
String[] drugsTrades = {"Hayamol 160 ", "Paradrin 160 "};
builder.setItems(drugsTrades, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
// dialog.getWindow().setBackgroundDrawableResource(R.color.translucent_black);
dialog.show();
}
}
}
return true;
}
});

但是(if语句(看到了(仅仅(第一部分";扑热息痛";并且没有看到第二部分";160〃;

用此代码替换整个代码。

.......
childObjects.add(new ChildObject(cetamol + " " + syr + " 160 " + mg5ml
, cetamolDoseMini160));
..........

elv = findViewById(R.id.elv);
elv.setOnGroupExpandListener(onGroupExpandListenser);
MyExpandableAdapter adapter = new MyExpandableAdapter(this, getData());
elv.setAdapter(adapter);
elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
for (int i = 0; i < ((ViewGroup) v).getChildCount(); ++i) {
View nextChild = ((ViewGroup) v).getChildAt(i);
if (nextChild.getId() == R.id.txtChildName) {
String data = ((TextView) nextChild).getText().toString();
String paracetamol = getResources().getString(R.string.Paracetamol);

if (data.contains(paracetamol) && data.contains("160")) {
AlertDialog.Builder builder = new AlertDialog.Builder(Analgesics.this);
builder.setTitle(" Paracetamol 160:");
String[] drugsTrades = {"Hayamol 160 ", "Paradrin 160 "};
builder.setItems(drugsTrades, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
// dialog.getWindow().setBackgroundDrawableResource(R.color.translucent_black);
dialog.show();
}
}
}
return true;
}
});

相关内容

  • 没有找到相关文章

最新更新