2017-02-17 16 views
1

jsonデータを表示するためにタブ付きアクティビティで複数のフラグメントを使用しています。
応答がすべてのフラグメントで受信されるたびにプログレスバーを表示します。 progressDialog使用して、このようなもので Retrofit 2 - 進行状況バーを表示する方法JSONレスポンス受信時

+0

進捗バーを表示しようとしましたが、xmlで宣言しましたが、できませんでした –

+0

@ルーカニコレッティ進捗バーを進捗ダイアログに表示しませんか?出来ますか? –

+0

あなたは既に答えを受け入れました。別の解決策が必要な場合は、別のものを投稿してください。 –

答えて

7

private void loadJSON() { 
 
    Retrofit retrofit = new Retrofit.Builder() 
 
    .baseUrl(BASEURL) 
 
    .addConverterFactory(GsonConverterFactory.create()) 
 
    .build(); 
 
    newsAPI = retrofit.create(NewsAPI.class); 
 
    Call <JSONResponse> call = 
 
    newsAPI.topNews("soure", "api-key"); 
 

 
    call.enqueue(new Callback <JSONResponse>() { 
 

 
     @Override 
 
     public void onResponse(Call <JSONResponse> call, Response <JSONResponse> response) { 
 

 
     Log.v("this", "Yes!"); 
 
     } 
 
    } 
 

 
    @Override public void onFailure(Call <JSONResponse> call, Throwable t) { 
 
     Log.v("this", "No Response!"); 
 
    } 
 
    });
、:あなたのレイアウト

<ProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/progressBarStyle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="?attr/actionBarSize" 
     android:layout_weight="1" /> 

private void loadJSON() { 
     Retrofit retrofit = new Retrofit.Builder() 
       .baseUrl(BASEURL) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .build(); 
     newsAPI = retrofit.create(NewsAPI.class); 
     Call <JSONResponse> call = 
       newsAPI.topNews("soure", "api-key"); 

     // Set up progress before call 
     final ProgressDialog progressDoalog; 
     progressDoalog = new ProgressDialog(MainActivity.this); 
     progressDoalog.setMax(100); 
     progressDoalog.setMessage("Its loading...."); 
     progressDoalog.setTitle("ProgressDialog bar example"); 
     progressDoalog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
     // show it 
     progressDoalog.show(); 

     call.enqueue(new Callback <JSONResponse>() { 

      @Override 
      public void onResponse(Call <JSONResponse> call, Response <JSONResponse> response) { 
       // close it after response 
       progressDoalog.dismiss(); 
       Log.v("this", "Yes!"); 
      } 
     } 

     @Override public void onFailure(Call <JSONResponse> call, Throwable t) { 
      // close it after response 
      progressDoalog.dismiss(); 
      Log.v("this", "No Response!"); 
     } 
    }); 
+0

ビンゴ!私の問題を解決しました...ダイアログではなく円形のプログレスバーを表示できますか? –

+0

ダイアログではなく進捗バーを表示したい。出来ますか? –

0

シンプルなトリック プログレスバーをプログレスバーを初期化

loadProgress = (ProgressBar) findViewById(R.id.progressBar); 

最後に、JSONの負荷がJSONデータの読み込みが完了すると、最終的に行って、いくつかのユーザーとの対話にそれが見えるように、その後

loadProgress.setVisibility(View.Gone); 

を競った後、それがなくなってします。シンプルな偽のトリック

関連する問題