AndroidDialogFragment的视图不更新
创始人
2024-10-07 11:30:30
0

如果在使用DialogFragment时,发现视图不更新,可以尝试在onCreateDialog方法中设置更新相关的代码。

例如:

public class ExampleDialogFragment extends DialogFragment {
    private TextView mTextView;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();

        View view = inflater.inflate(R.layout.fragment_dialog, null);
        mTextView = view.findViewById(R.id.text_view);
        mTextView.setText("Old text");

        Button button = view.findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTextView.setText("New text");
            }
        });

        builder.setView(view)
                .setTitle("Example Dialog")
                .setPositiveButton("OK", null)
                .setNegativeButton("Cancel", null);

        return builder.create();
    }
}

在这个例子中,我们可以看到在调用setText方法之后,将TextView的内容更新为'New text”。

这样就可以解决DialogFragment视图不更新的问题了。

相关内容

热门资讯

透视辅助!wpk透视是真的假的... 透视辅助!wpk透视是真的假的(透视)原来真的是有挂(详细辅助透明挂教程)1、首先打开最新版本,在首...
关于!pokemmo脚本辅助器... 1、关于!pokemmo脚本辅助器下载,aapoker如何设置胜率,黑科技教程(有挂软件)。2、po...
透视工具!hhpoker视频巡... 透视工具!hhpoker视频巡查真的假的(透视)切实真的是有挂(详细辅助详细教程)是一种具有地方特色...
玩家必看教程!we-poker... 玩家必看教程!we-poker辅助器,pokerworld软件,安装教程(有挂透视);建议优先通过w...
透视最新!wepoker有辅助... 透视最新!wepoker有辅助工具吗(透视)其实有挂(详细辅助透视教程)1、每一步都需要思考,不同水...
必看攻略!wepoker看底牌... 必看攻略!wepoker看底牌,wepoker怎么破解游戏,教你攻略(有挂方法)关于wepoker怎...
普及知识!hhpoker哪个俱... 普及知识!hhpoker哪个俱乐部靠谱,德州辅助工具到底怎么样,必胜教程(有挂技巧);1.德州辅助工...
透视代打!哈糖大菠萝攻略(透视... 透视代打!哈糖大菠萝攻略(透视)真是有挂(详细辅助wpk教程);1、透视代打!哈糖大菠萝攻略(透视)...
总算明白!wepoker私人局... 总算明白!wepoker私人局辅助,红龙poker作弊指令,必胜教程(有挂技巧)1、不需要AI权限,...
透视代打!wepoker透视底... 透视代打!wepoker透视底牌(透视)一直真的是有挂(详细辅助力荐教程);1、该软件可以轻松地帮助...