2016-05-13 4 views
-1

MainActivity.classアダプターは接続されていません。スキップレイアウト:RecyclerView

public class MainActivity extends AppCompatActivity { 

    private static final String TAG = "ERROR"; 

    private final static String API_KEY = "xxxxxxxxxxxxxx"; 

    int totalpage; 
    int page; 

    int firstVisibleItem, visibleItemCount, totalItemCount; 

    ProgressBar progressBar; 

    RecyclerView recyclerView; 
    MoviesAdapter moviesAdapter; 

    private boolean makeCall = false; 
    boolean onLoding = false; 


    List<Movie> movies = new ArrayList<Movie>(); 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     recyclerView = (RecyclerView) findViewById(R.id.movies_recycler_view); 
     recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this)); 

     loadData(); 
     moviesAdapter = new MoviesAdapter(movies, R.layout.list_item_movie, MainActivity.this); 
     moviesAdapter.notifyDataSetChanged(); 
     recyclerView.setAdapter(moviesAdapter); 

    } 


    public void loadData() { 

     ApiInterface apiService = 
       ApiClient.getClient().create(ApiInterface.class); 

     Call<String> call = apiService.getTopRatedMovies(API_KEY); 


     call.enqueue(new Callback<String>() { 
      @Override 
      public void onResponse(Call<String> call, Response<String> response) { 

       Log.i("RetrofitOnly", response.body()); 


       String responceString = response.body(); 
       JSONObject main; 

       try { 
        main = new JSONObject(responceString); 
        page = main.getInt("page"); 
        totalpage = main.getInt("total_pages"); 
        Log.d("PageNo==>>", page + ""); 
        JSONArray jsonArray = main.getJSONArray("results"); 

        try { 
         Log.d("Array==>>", jsonArray.toString() + ""); 


         movies = LoganSquare.parseList(jsonArray.toString(), Movie.class); 

         if (movies == null) { 
          Toast.makeText(getApplicationContext(), "NULL", Toast.LENGTH_LONG).show(); 
         } else { 
          Toast.makeText(getApplicationContext(), "NULL NOT", Toast.LENGTH_LONG).show(); 
         } 


        } catch (IOException e) { 
         e.printStackTrace(); 
        } 

       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 

      } 

      @Override 
      public void onFailure(Call<String> call, Throwable t) { 

      } 
     }); 

    } 

} 

エラー

5月13日02:25:15.145 23598から23598/com.example.dhaval.retrofitonly E/RecyclerView:添付なしアダプタ;レイアウトをスキップする

05-13 02:25:15.481 23598-23598/com.example.dhaval.retrofitonly E/RecyclerView:アダプタが接続されていません。レイアウトをスキップする

ありがとうございます!!!

答えて

1

メイン/ UIスレッドのloadData()の消去方法は、改造2ではASYNCHRONOUSなので、メインスレッドで行う必要はありません。

参照改修 - >https://futurestud.io/blog/retrofit-synchronous-and-asynchronous-requests

notifyDataSetChanged()アダプタ方法onResponse()で、あなたはあなたのリストにあなたの結果を記入した後。

movies.addAll(response.body().getResults()); moviesAdapter.notifyDataSetChanged();

関連する問題