我如何在onCreate Java生命周期中调用view方法?

问题描述 投票:0回答:1

我想使用setText时遇到问题,但是当直接在onCreate上调用它不能吗?

这是我的方法:

    public void onSendData(View view) {
        long seek = videoView.getCurrentPosition();
        WritableMap args = Arguments.createMap();
        args.putInt("index", index);
        args.putInt("seek", (int) seek);
        args.putString("type", "paused");
        args.putString("name", playingVideo.getString("name"));
        args.putString("category_name", playingVideo.getString("category_name"));
        args.putString("date", playingVideo.getString("date"));
        sendEvent(reactContext, "onSendData", args);
        textName.setText(playingVideo.getString("name") + " " + playingVideo.getString("category_name"));
        textDate.setText(playingVideo.getString("date"));
        textCustomerName.setText(playingVideo.getString("customer_name"));
        textEstimate.setText(playingVideo.getString("estimate"));
        textPaid.setText(playingVideo.getString("paid"));
        textPrice.setText(playingVideo.getString("price"));
        textAddress.setText(playingVideo.getString("address"));
        textLongAddress.setText(playingVideo.getString("long_address"));


    }

这是我调用onCreate生命周期时的代码:

    public void onCreate() {
        super.onCreate();
        onSendData();
      ........
      .....
     }

请帮助,非常感谢。

java android android-lifecycle
1个回答
0
投票

不确定是什么问题,但我会这样:

public void onCreate() {
        super.onCreate();
        loadViews();       //create instance of view objects textName, textDate, etc. 
        onSendData(null);  //passing View as null 
      ........
      .....
     }
© www.soinside.com 2019 - 2024. All rights reserved.