DialogFragment的使用

来源:互联网 发布:淘宝情趣丝袜女模特 编辑:程序博客网 时间:2024/05/22 13:24
public class EditNameDialogFragment extends DialogFragment {    private Button button;    private EditText id_txt_your_name;    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {        View view = inflater.inflate(R.layout.fragment_edit_name, container);        button = view.findViewById(R.id.id_sure_edit_name);        id_txt_your_name = view.findViewById(R.id.id_txt_your_name);        button.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                listener.returnRefresh(id_txt_your_name.getText().toString());            }        });        return view;    }    //刷新数据    private static refreshOnDisplayListener listener;    public interface refreshOnDisplayListener {        public void returnRefresh(String str);    }    public static void setOnDisplayRefreshListener(refreshOnDisplayListener myListener) {        listener = myListener;    }}



<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content" >    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="match_parent">        <TextView            android:layout_margin="10dp"            android:id="@+id/id_label_your_name"            android:layout_width="wrap_content"            android:layout_height="32dp"            android:gravity="center_vertical"            android:text="Your name:" />        <EditText            android:layout_marginTop="10dp"            android:id="@+id/id_txt_your_name"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_toRightOf="@id/id_label_your_name"            android:imeOptions="actionDone"            android:inputType="text" />        <Button            android:onClick="onFinish"            android:layout_centerHorizontal="true"            android:id="@+id/id_sure_edit_name"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_below="@id/id_txt_your_name"            android:text="ok" />    </RelativeLayout></android.support.v7.widget.CardView>


EditNameDialogFragment.setOnDisplayRefreshListener(new EditNameDialogFragment.refreshOnDisplayListener() {            @Override            public void returnRefresh(String str) {                textview.setText(str);                editNameDialog.dismiss();            }        });


public void showEditDialog(View view) {        editNameDialog = new EditNameDialogFragment();        editNameDialog.show(getSupportFragmentManager(), "EditNameDialog");    }


原创粉丝点击