更新可运行对象内的两个 TextView

Update two TextViews inside a runnable

我可以更新一个runnable 中的两个textview 吗? 因为我的代码只能更新一个textview。 我得到了更新 2 个包含照片 EXIF 数据中的地址和日期的文本视图的方法。

public void launchRingDialog() {

        final ProgressDialog ringProgressDialog = ProgressDialog.show(ReportIncident.this, "Please wait ...", "Rendering Image EXIF Data ...", true);

        ringProgressDialog.setCancelable(false);

        new Thread(new Runnable() {

            @Override

            public void run() {

                try {





                    Thread.sleep(5000);
                    loadExifData();
                    r.setDate(mExif.getAttribute(ExifInterface.TAG_DATETIME));
                    tvLocation.setText(getaddress());
                    tvTime.setText(r.getStringDate());
                    r.setLati(Double.parseDouble(mExif.getAttribute(ExifInterface.TAG_GPS_LATITUDE)));
                    r.setLongi(Double.parseDouble(mExif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE)));



                } catch (Exception e) {


                }

                ringProgressDialog.dismiss();

            }

        }).start();

    }

您不能在与 Android 中的 UI 线程不同的线程中更新 UI。为此,您可以使用的一种简单方法是:

Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable(){
    tvLocation.setText(getaddress());
    tvTime.setText(r.getStringDate());
});