Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: incompatible types: com.google.firebase.database.core.Context cannot be converted to android.content.Context #52

Open
Jsamouil opened this issue Feb 3, 2020 · 1 comment

Comments

@Jsamouil
Copy link

Jsamouil commented Feb 3, 2020

No description provided.

@Jsamouil
Copy link
Author

Jsamouil commented Feb 3, 2020

import android.view.LayoutInflater;
//import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.fastfood1.Common.Common;
import com.example.fastfood1.Model.CategoryModel;
import com.example.fastfood1.R;
import com.google.firebase.database.core.Context;

import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class MyCategoriesAdapter extends RecyclerView.Adapter<MyCategoriesAdapter.MyViewHolder> {

Context context;
List<CategoryModel> categoryModelList;

public MyCategoriesAdapter(Context context, List<CategoryModel> categoryModelList) {
    this.context = context;
    this.categoryModelList = categoryModelList;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    return new MyViewHolder(LayoutInflater.from(context)
            .inflate(R.layout.layout_category_item, parent, false));
}

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
    Glide.with(context).load(categoryModelList.get(position).getImage())
            .into(holder.category_iamge);
    holder.category_name.setText(new StringBuilder(categoryModelList.get(position).getName()));
}

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

public class MyViewHolder extends RecyclerView.ViewHolder {
    Unbinder unbinder;
    @BindView(R.id.img_category)
    ImageView category_iamge;
    @BindView(R.id.txt_category)
    TextView category_name;
    public MyViewHolder(@NonNull View itemView) {
        super(itemView);
        unbinder  = ButterKnife.bind(this,itemView);
    }
}


@Override
public int getItemViewType(int position) {
    if(categoryModelList.size() == 1)
    {
        return Common.DEAFAULT_COLUMN_COUNT;
    }
    else
    {
        if(categoryModelList.size() % 2 == 0)
            return Common.DEAFAULT_COLUMN_COUNT;
        else
            return (position > 1 && position == categoryModelList.size() - 1) ? Common.FULL_WIDTH_COLUMN:Common.DEAFAULT_COLUMN_COUNT;
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant