我是原生 android developpement 的新手,我不知道如何更新我的 ui 以响应状态变化。在这种情况下,我希望我View返回一个 TextView ifIs loading == true然后当IsLoading我的 View 更新为 false 时返回view这是我的代码:public class FlutterPdfView implements PlatformView, MethodCallHandler { private PDFView view; private String path; private File pdf; private boolean isLoading; private final MethodChannel methodChannel; private OnRenderListener onRenderListener; private TextView textView; private PDFView.OnLayoutChangeListener onLayoutChangeListener; FlutterPdfView(final Context context, int id, Object args, BinaryMessenger messenger ) { try { methodChannel = new MethodChannel(messenger, "\"plugins.smartwork.flutter_pdfview/pdfview_" + id); isLoading = true; textView = new TextView(context); onRenderListener = new OnRenderListener() { @Override public void onInitiallyRendered(int nbPages) { isLoading = false; } }; view = new PDFView(context, null); path = (String) args; pdf = new File(path); onLayoutChangeListener = new PDFView.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { recycleView(); } }; }finally { initView(); } } @Override public View getView() { if(isLoading == true) { return textView; } else { return view; } } private void recycleView() { view.recycle(); view.fromFile(pdf).defaultPage(0).load(); } private void initView() { view.addOnLayoutChangeListener(onLayoutChangeListener); view.fromFile(pdf).defaultPage(0).onRender(onRenderListener).load(); }}是的,它很乱,但我是初学者 ^^感谢您的帮助 !
1 回答
qq_笑_17
TA贡献1818条经验 获得超7个赞
设置 isLoading false 后调用 invalidate(); 它使视图重绘自己。
@Override
public View getView() {
if(isLoading == true) {
return textView;
} else {
return view;
invalidate();
}
}
添加回答
举报
0/150
提交
取消