Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 视图未从回调方法更新_Android_Database_Sqlite_Listener - Fatal编程技术网

Android 视图未从回调方法更新

Android 视图未从回调方法更新,android,database,sqlite,listener,Android,Database,Sqlite,Listener,我正在从数据库中提取数据。我的视图仅在第一次打开“活动”时更新。然后,当我再次打开活动时,我的视图不会更新。(活动将再次启动,因此将再次调用onCreate(),所有设置都相同)如果设置文本后我getText(),我会在日志中获得正确的值,但视图中不会显示任何内容 以下是我的代码片段: //My Call Back method @Override public void onRatingDataLoaded(ReviewJsonModel review) {

我正在从数据库中提取数据。我的视图仅在第一次打开“活动”时更新。然后,当我再次打开活动时,我的视图不会更新。(活动将再次启动,因此将再次调用
onCreate()
,所有设置都相同)如果设置文本后我
getText()
,我会在日志中获得正确的值,但视图中不会显示任何内容

以下是我的代码片段:

//My Call Back method    
@Override
    public void onRatingDataLoaded(ReviewJsonModel review) {

        int ratingCount = 0, ownRating = 0;
        String averageRating = "0";
        if (review != null) {
            ratingCount = review.review_count;
            DecimalFormat format = new DecimalFormat("##.00");

            averageRating = format.format(review.rating);
            if (review.ownreviews != null) {

                try {
                    ownRating = Integer.parseInt(review.ownreviews.rating);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }                
            }
        } else {
            // do something
        }

        mTotalRatingCount.setText(String.format(getResources().getString(R.string.review_count), ratingCount));
        mAverageRating.setText(averageRating);

// Log.v("LoggingReview", mTotalRatingCount.getText().toString().trim);
        myRating.setRating(ownRating);        
    }
//这里我设置listner并加载数据

public void loadReviewData(RatingDataLoadListener listener, int destinationId) {
        if (mDataLoadListener == null)
            mDataLoadListener = listener;

        new getReviews().execute(destinationId);

    }
接下来是我的任务

private class getReviews extends AsyncTask<Integer, Void, ReviewJsonModel> {

        @Override
        protected ReviewJsonModel doInBackground(Integer... integers) {
            Cursor appCursor = mRatingApi.getDestinationReview(integers[0]);

            ReviewJsonModel mReviewData = new ReviewJsonModel();
            if (appCursor != null && appCursor.getCount() > 0) {
                appCursor.moveToFirst();
                while (!appCursor.isAfterLast()) {
                    mReviewData = getDocument(appCursor);
                    appCursor.moveToNext();

                }
                appCursor.close();
            }

            return mReviewData;
        }

        @Override
        protected void onPostExecute(ReviewJsonModel result) {
            super.onPostExecute(result);

            if (mDataLoadListener != null)
                mDataLoadListener.onRatingDataLoaded(result);
        }
    }
私有类getReviews扩展异步任务{
@凌驾
受保护的ReviewJsonModel doInBackground(整数…整数){
Cursor-appCursor=mRatingApi.getDestinationReview(整数[0]);
ReviewJsonModel mReviewData=新的ReviewJsonModel();
if(appCursor!=null&&appCursor.getCount()>0){
appCursor.moveToFirst();
而(!appCursor.isAfterLast()){
mReviewData=getDocument(appCursor);
appCursor.moveToNext();
}
appCursor.close();
}
返回mReviewData;
}
@凌驾
受保护的void onPostExecute(ReviewJsonModel结果){
super.onPostExecute(结果);
if(mDataLoadListener!=null)
mDataLoadListener.onRatingDataLoaded(结果);
}
}

找不到问题的原因。感谢您的帮助

似乎存在回调问题,请尝试下面的操作

public void loadReviewData(RatingDataLoadListener listener, int destinationId) {
    mDataLoadListener = listener; 
    new getReviews().execute(destinationId); 
}

在textview.com上设置值后,是否可以调用mAverageRating.invalidate(),从何处调用getReviews asyncTask?,同时确保将侦听器回调mDataLoadListener设置为asyncTask。如果可能,请提供oncreate方法。下一个问题是你的目标是什么?你想让oncreate方法不被第二次调用吗?@faldujaldeph我已经试过了。无法使我们工作。@AshishJohn从mDataLoad侦听器中删除空检查