[英]Change TextView from Dialog EditText
So i have a dialog that shows up in the fragment. 所以我有一个显示在片段中的对话框。 i need to change a textview with a dialog.
我需要用对话框更改textview。 so i created a dialog with an editText, but i am not sure how do i pass the char sequence from dialog to fragment.
所以我创建了一个带有editText的对话框,但我不知道如何将char序列从对话框传递到片段。
rename_dialog_edit
is EditText from dialog rename_dialog_edit
是来自对话框的EditText
GroupName
is TextView from fragment GroupName
是片段中的TextView
on positive click: 积极点击:
GroupName.setText((CharSequence) rename_dialog_edit);
after positive click my textview gets empty. 积极点击后,我的textview变空。 how do i properly set it?
我该如何正确设置呢?
Update 更新
protected static TextView GroupName;
protected static EditText rename_dialog_edit;
In the onCreateView i have: 在onCreateView我有:
TextView GroupName = (TextView) view.findViewById(R.id.group_details_name);
EditText rename_dialog_edit = (EditText) view.findViewById(R.id.groupdetails_rename);
here is my onCreateDialog: 这是我的onCreateDialog:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
//int title = getArguments().getInt("title");
return builder.setView(inflater.inflate(R.layout.group_details_rename_dialog, null))
//.setIcon(R.drawable.logo)
//.setTitle(R.string.groupDetails_rename)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
doPositiveClick();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
doNegativeClick();
}
})
.create();
}
and here is my positive click: 这是我的积极点击:
public static void doPositiveClick() {
GroupName.setText(rename_dialog_edit.getText().toString());
//Log.i("FragmentAlertDialog", "Positive click!");
}
Get the Text from the EditText
like: 从
EditText
获取文本,如:
String str= ((EditText)findViewById(R.id.rename_dialog_edit)).getText().toString();
Set it to textView like: 将其设置为textView,如:
TextView text = (TextView) findViewById(R.id.this_is_the_id_of_your_textview);
text.setText(str);
have you tried something like this? 你试过这样的事吗?
Update : 更新 :
Inside the button listener just do: 在按钮监听器内部只做:
GroupName.setText(rename_dialog_edit.getText().toString())
Also try to be consistent with of camelCase variable names in Java. 还尝试与Java中的camelCase变量名一致。 It might be a good practice.
这可能是一个很好的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.