[英]Why can't I find edittext and textview inside the dialog box
我试图将edittext放在一个对话框中。 执行时仅显示按钮,但不显示我在 xml 中定义的 edittext 和 textview。 我是初学者,有人可以帮我解决这个问题。
nametv.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final AlertDialog.Builder builder = new AlertDialog.Builder(SearchDistibutorProduct.this);
LayoutInflater layoutInflater = getLayoutInflater();
final View customlayout = layoutInflater.inflate(R.layout.update,null);
builder.setView(customlayout);
/*builder.create();
builder.show();*/
// builder.setCancelable(false);
// builder.setTitle("UPdate values");
final TextView textView = customlayout.findViewById(R.id.updatetv);
final EditText editText = customlayout.findViewById(R.id.updateet);
Button button =customlayout.findViewById(R.id.updatebtn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText(workerlist.get(0).getName());
final String nameupdate = editText.getText().toString();
String name= workerlist.get(0).getName();
String id= workerlist.get(0).getId();
if(!name.equals( nameupdate) ) {
HashMap hashMap = new HashMap();
hashMap.put("name", nameupdate);
databaseworker = FirebaseDatabase.getInstance().getReference("Patient");
databaseworker.child(id).updateChildren(hashMap);
builder.setCancelable(true);
}
else {
builder.setCancelable(true);
Toast.makeText(SearchDistibutorProduct.this, "no change is done", Toast.LENGTH_SHORT).show();
}
}
});
builder.create();
builder.show();
return false;
}
});
XML 文件有问题,试试这个
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/updatetv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/updateet"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/updatebtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.