从片段外部更新dialogfragment视图

时间:2016-06-15 11:54:39

标签: android android-fragments android-dialogfragment event-bus greenrobot-eventbus

是否可以更新对话片段的任何视图,例如来自父活动或片段的文本视图?我有一个progressdialog,一旦从服务加载一些文本并显示在textview中,就应该被解雇。

确实收到了数据,但是progressdialog从未被删除,也没有显示texview。

这是我的dialogfragment代码:

@SuppressLint("ValidFragment")
public class ArtistInfoDialog extends DialogFragment {

    ImageButton close;
    TextView title;
    TextView artist;
    ImageView art;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.artist_info_layout, container, false);

        artistInfo = (TextView) view.findViewById(R.id.artist_info);
        close = (ImageButton) view.findViewById(R.id.close);
        loadingIndicator = (AVLoadingIndicatorView) view.findViewById(R.id.loadingIndicator);
        title = (TextView) view.findViewById(R.id.title);
        artist = (TextView) view.findViewById(R.id.artist);
        art = (ImageView) view.findViewById(R.id.art);

        Track track = NakedGroove.getCurrentPlaylist().get(NakedGroove.getCurrentIndex());

        title.setText(track.getTitle());
        artist.setText(track.getArtist());

        if (!track.getImages().isEmpty())
            Picasso.with(getActivity()).load(track.getMediumImage()).fit().centerCrop().error(R.drawable.no_cover).placeholder(R.drawable.no_cover).into(art);
        else
            Picasso.with(getActivity()).load(R.drawable.no_cover).fit().centerCrop().into(art);

        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        return view;
    }
}

EventBus代码如下:

  @Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(ArtistMetadataEvent metadataEvent) {
    String info = metadataEvent.bio;

    if (artistInfoDialog != null) {
        loadingIndicator.setVisibility(View.GONE);
        artistInfo.setVisibility(View.VISIBLE);

        if (!TextUtils.isEmpty(info)) {
            artistInfo.setText(info);
        } else {
            artistInfo.setText("Artist information unavailable");
        }
    }
}

0 个答案:

没有答案