0

카드 목록을 보여줘야하는 recyclerView가 있습니다. 레시피의 arrayList가 어댑터로 전달되어 어댑터를 카드보기로 표시하게되면 디버깅의 모든 항목이 문제가없는 것처럼 보이지만 화면에 아무 것도 표시하지 않습니다. ViewHolder :recyclerView는 카드보기를 표시합니다. 아무 것도 표시되지 않습니다

import android.support.v7.widget.RecyclerView; 
import android.view.View; 
import android.widget.ImageView; 
import android.widget.TextView; 

import com.example.nd.ameer.bake.R; 

public class RecipeViewHolder extends RecyclerView.ViewHolder { 

    public TextView titleTextView; 
    public ImageView coverImageView; 

    public RecipeViewHolder(View v) { 
     super(v); 
     titleTextView = (TextView) v.findViewById(R.id.titleTextView); 
     coverImageView = (ImageView) v.findViewById(R.id.recipeImageView); 
    } 
} 

어댑터 :

import android.content.Context; 
import android.support.v7.widget.RecyclerView; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

import com.bumptech.glide.Glide; 
import com.example.nd.ameer.bake.R; 
import com.example.nd.ameer.bake.models.Recipe; 
import com.example.nd.ameer.bake.views.holders.RecipeViewHolder; 

import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.ArrayList; 

public class RecipeAdapter extends 

RecyclerView.Adapter<RecipeViewHolder> { 


    ArrayList<Recipe> recipes = new ArrayList<>(); 
    Context context; 

    public RecipeAdapter(ArrayList<Recipe> recipes, Context context) { 
     this.recipes = recipes; 
     this.context = context; 
    } 

    @Override 
    public RecipeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View view = LayoutInflater.from(context).inflate(R.layout.recipe_item, parent, false); 
     return new RecipeViewHolder(view); 
    } 

    @Override 
    public void onBindViewHolder(RecipeViewHolder holder, int position) { 

     holder.coverImageView.setImageResource(R.color.colorPrimaryLight); 
     holder.titleTextView.setText(recipes.get(position).getName()); 
    } 

    @Override 
    public int getItemCount() { 
     return recipes.size(); 
    } 
} 

조각 onCreateView :

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    rootView = inflater.inflate(R.layout.fragment_recipe, container, false); 

    createRecipes(); 

    recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_recipe); 
    recyclerView.setHasFixedSize(true); 
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 
    if (recipes.size() > 0 & recyclerView != null) { 
     recyclerView.setLayoutManager(layoutManager); 
     recyclerView.setAdapter(new RecipeAdapter(recipes, getContext())); 
    } 
    return rootView; 
} 

메소드를 createRecipes(); 조리법 목록을 만든 다음 어댑터로 전달합니다.

as you can see, the recipes size is 4, so it's not the problem

+0

'recipes' 목록의 크기가 0이 아닌가? –

+0

그래, 항상 4, 같은 목록 –

+0

당신은 당신의 createRecipes() 코드와 logcat 로그를 게시 할 수있다 –

답변

0

지금까지 문제의 원인을 알지 못했다,하지만 난 어댑터와 내부 클래스와 요리법 조각에 뷰 홀더 모두를 이동하고,이 문제를 해결했다.

관련 문제