我是原生 android developpement 的新手,我不知道如何更新我的 ui 以響應(yīng)狀態(tài)變化。在這種情況下,我希望我View返回一個(gè) TextView ifIs loading == true然后當(dāng)IsLoading我的 View 更新為 false 時(shí)返回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(); }}是的,它很亂,但我是初學(xué)者 ^^感謝您的幫助 !
1 回答

qq_笑_17
TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊
設(shè)置 isLoading false 后調(diào)用 invalidate(); 它使視圖重繪自己。
@Override
public View getView() {
if(isLoading == true) {
return textView;
} else {
return view;
invalidate();
}
}
添加回答
舉報(bào)
0/150
提交
取消