I'm using Retrofit, picasso and recyclerview.But the below error is coming.
Process: com.example.user.recyclerview, PID: 4871
java.lang.StackOverflowError
MainActivity.class
public class MainActivity extends AppCompatActivity
{
private RecyclerView recyclerView;
private DataAdapter dataAdapter;
private List<ModelData> modelDataList;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.card_recycle_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
getPopularMovies();
}
private void getPopularMovies()
{
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://pratikbutani.x10.mx")
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitInterface service = retrofit.create(RetrofitInterface.class);
Call<ModelDataList> call =service.getJSON();
call.enqueue(new Callback<ModelDataList>()
{
#Override
public void onResponse(Call<ModelDataList> call, Response<ModelDataList> response)
{
ModelDataList modelDataList = response.body();
dataAdapter = new DataAdapter(modelDataList.getResults());
recyclerView.setAdapter(dataAdapter);
}
#Override
public void onFailure(Call<ModelDataList> call, Throwable t)
{
Log.d("Main","failure");
}
});
}
}
ModelDataList.java
public class ModelDataList
{
private List<ModelData> results;
public List<ModelData> getResults()
{
return results;
}
}
DataAdapter.java
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder>
{
private List<ModelData> modelDataList;
private LayoutInflater layoutInflater;
private Context context;
public DataAdapter(List<ModelData> modelDataList)
{
this.context = new AppCompatActivity();
this.modelDataList = modelDataList;
this.layoutInflater = LayoutInflater.from(context);
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View view = layoutInflater.inflate(R.layout.card_view, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position)
{
ModelData modelData = modelDataList.get(position);
holder.textView.setText(modelData.getName());
Picasso.with(context).load(String.valueOf(modelData.getDisplay_pic())).placeholder(R.color.colorAccent).into(holder.imgview);
}
#Override
public int getItemCount()
{
return modelDataList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder
{
private ImageView imgview;
private TextView textView;
public ViewHolder(View itemView)
{
super(itemView);
imgview = (ImageView) itemView.findViewById(R.id.tv_image);
textView = (TextView) itemView.findViewById(R.id.tv_name);
}
}
}
Not sure about your StackOverflowError issue. One issue is how you get...context. You can get context from view instead of "this.context = new AppCompatActivity();"
ex:
LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view, parent, false);
Picasso.with(holder.imgview.getContext()).load(String.valueOf(modelData.getDisplay_pic())).placeholder(R.color.colorAccent).into(holder.imgview);
Related
I have a problem in my code, I want to send the data I clicked from the RecyclerView to edit text in the same activity
My adapter:
public class RecyclerViewAdapter1 extends RecyclerView.Adapter<RecyclerViewAdapter1.ViewHolder> {
private Context context;
private List<Result> results;
public RecyclerViewAdapter1(Context context, List<Result> results) {
this.context = context;
this.results = results;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.arraylist1, parent,false);
ViewHolder holder = new ViewHolder(v);
return holder;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
Result result = results.get(position);
holder.textViewid.setText(result.getRef_desa_id());
holder.textViewNm_desa.setText(result.getNama_desa());
}
#Override
public int getItemCount() {
return results.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
#BindView(R.id.txtid)
TextView textViewid;
#BindView(R.id.txtnm_desa)
TextView textViewNm_desa;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
#Override
public void onClick(View v) {
String id = textViewid.getText().toString();
Intent i = new Intent(context, DaftarDukaActivity2.class);
((Activity)context).finish();
i.putExtra("id", id);
context.startActivity(i);
}
}
}
In the code above, my coding has succeeded in displaying data to another Edit text activity. I want to ask, how to send data from the RecyclerView I clicked to EditText in the same activity?
Do you want editText.setText() from reacyclerview adapter? You can do like this:
public class RecyclerViewAdapter1 extends RecyclerView.Adapter<RecyclerViewAdapter1.ViewHolder> {
private Context context;
private List<Result> results;
private EditText editText;
public RecyclerViewAdapter1(Context context, List<Result> results,EditText editText) {
this.context = context;
this.results = results;
this.editText=editText;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.arraylist1, parent,false);
ViewHolder holder = new ViewHolder(v);
return holder;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
Result result = results.get(position);
holder.textViewid.setText(result.getRef_desa_id());
holder.textViewNm_desa.setText(result.getNama_desa());
}
#Override
public int getItemCount() {
return results.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
#BindView(R.id.txtid)
TextView textViewid;
#BindView(R.id.txtnm_desa)
TextView textViewNm_desa;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
#Override
public void onClick(View v) {
String id = textViewid.getText().toString();
editText.setText(id);
}
}
}
Usage
public class MainActivity extends AppCompatActivity{
private Context context=this;
private List<Result> results;
private EditText editText;
private RecyclerView rec;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText=findViewById(R.id.my_edit_text_id_in_xml);
rec=findViewById(R.id.my_recycler_view_id);
// add items to your result List
rec.setAdapter(new RecyclerViewAdapter1(context,results,editText));
rec.setLayoutManager(new LinearLayoutManager(context));
}
}
I'm trying to add a recyclerview to a fragment, but somehow there happens to be an error in the adapter.
I think it is the way in which I bind it, and I can't figure out the solution to it. Can anybody help me solve the issue?
here's my adapter:
public class MyLeaguesListAdapter extends
RecyclerView.Adapter<MyLeaguesListAdapter.MyViewHolder>{
List<MyContest> listItems;
Context context;
public interface OnItemClickListener {
void onItemClick(View v,int pos);
}
public MyLeaguesListAdapter(List<MyContest> listItems,Context context){
this.listItems = listItems;
this.context = context;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v;
v = LayoutInflater.from(context).inflate(R.layout.my_contest_item,parent,false);
MyViewHolder myViewHolder = new MyViewHolder(v);
return myViewHolder;
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView leagueName,playerName,prizePool,playerRank,playerPoints,entryFee,spots;
OnItemClickListener onItemCheckListener;
public MyViewHolder(View itemView) {
super(itemView);
leagueName = (TextView) itemView.findViewById(R.id.mc_contest_name);
playerName = (TextView) itemView.findViewById(R.id.mc_player_name);
prizePool = (TextView) itemView.findViewById(R.id.mc_prize_pool);
playerRank = (TextView) itemView.findViewById(R.id.mc_player_rank);
playerPoints = (TextView) itemView.findViewById(R.id.mc_player_points);
entryFee = (TextView) itemView.findViewById(R.id.mc_entry_fee);
spots = (TextView) itemView.findViewById(R.id.mc_spots);
itemView.setOnClickListener(this);
}
public void setItemClickListener(OnItemClickListener ic){
this.onItemCheckListener = ic;
}
#Override
public void onClick(View view) {
this.onItemCheckListener.onItemClick(view,getAdapterPosition());
}
}
#Override
public int getItemCount() {
return listItems.size();
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
MyContest listItem = listItems.get(position);
holder.leagueName.setText(listItem.getLeaguename());
holder.prizePool.setText(listItem.getPrizepool());
holder.playerPoints.setText(listItem.getScore());
holder.playerRank.setText(listItem.getRank());
holder.playerName.setText(listItem.getUsername());
holder.spots.setText(listItem.getSpots());
holder.entryFee.setText(listItem.getFee());
holder.setItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(View v, int pos) {
}
});
}
}
this is my fragment:
public class MyLeagues extends Fragment {
SharedPreferences sharedPreferences,ui;
int score,userid,i=0;
String username,lname,inviteCode;
List<MyContest> list_item;
MyLeaguesListAdapter adapter;
ProgressBar progressBar;
Sprite fadingCircle;
RecyclerView recyclerView;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_my_leagues,null);
ui = this.getActivity().getSharedPreferences("User",Context.MODE_PRIVATE);
userid = ui.getInt("userid",-1);
progressBar = (ProgressBar) view.findViewById(R.id.mcspin_kit);
fadingCircle = new FadingCircle();
progressBar.setIndeterminateDrawable(fadingCircle);
Log.d("eede", "onCreateView: "+inviteCode);
recyclerView = (RecyclerView) view.findViewById(R.id.mc_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));
list_item = new ArrayList<>();
getMYContests();
return view;
}
public void getMYContests(){
Call<MyContestResponse> call = RetrofitClient
.getInstance()
.getApi()
.getMycontests(userid);
call.enqueue(new Callback<MyContestResponse>() {
#Override
public void onResponse(Call<MyContestResponse> call, Response<MyContestResponse> response) {
list_item=response.body().getData();
adapter = new MyLeaguesListAdapter(list_item,getContext());
progressBar.setVisibility(View.INVISIBLE);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
#Override
public void onFailure(Call<MyContestResponse> call, Throwable t) {
Log.d("bruv", "onFailure: "+t);
}
});
}
}
error:
07-03 09:36:20.980 30095-30095/? E/AndroidRuntime: FATAL EXCEPTION:
main
Process: com.example.android.khelo, PID: 30095
android.content.res.Resources$NotFoundException: String resource ID #0xffffffff
at android.content.res.Resources.getText(Resources.java:363)
at android.widget.TextView.setText(TextView.java:6485)
at com.example.android.khelo.MyLeaguesListAdapter.onBindViewHolder(MyLeaguesListAdapter.java:75)
at com.example.android.khelo.MyLeaguesListAdapter.onBindViewHolder(MyLeaguesListAdapter.java:20)
from what I've read, the issue is with the way I bind the recylerview but I've not got a clear idea about where the issue actually lies.
It is possible that one or many of your listItem attributes return an integer like getScore and getFee. So let's look at the implementation of TextView.setText(int)
public final void setText(int resid) {
...
}
As you can see, it only accepts the int as a resource id like R.string.something.
So what you can do here is to make your int become string when setText like
holder.playerPoints.setText(listItem.getScore().toString());
I want to pull data http://jsonplaceholder.typicode.com/users but my code only get one person(name: Leanne Graham,username: Bret) I want to get all users. I create ServiceGenerator.java Call> placeHolderModel(); maybe this code may error.
MainActivity.java
public class MainActivity extends AppCompatActivity {
TextView textView ;
RecyclerView recyclerView ;
SimpleRecyclerAdapter simpleRecyclerAdapter ;
ArrayList<Person> arrayList ;
private LinearLayoutManager layoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(layoutManager);
arrayList=new ArrayList<Person>();
Factory.getInstance().placeHolderModel().enqueue(new Callback<List<PlaceHolderModel>>() {
#Override
public void onResponse(Call<List<PlaceHolderModel>> call, Response<List<PlaceHolderModel>> response) {
textView.setText(response.body().get(0).name);
simpleRecyclerAdapter= new SimpleRecyclerAdapter(response.body());
recyclerView.setAdapter(simpleRecyclerAdapter);
}
#Override
public void onFailure(Call<List<PlaceHolderModel>> call, Throwable t) {
}
});
}
}
SimpleRecyclerAdapter.java
public class SimpleRecyclerAdapter extends RecyclerView.Adapter<SimpleRecyclerAdapter.ViewHolder> {
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView isim ;
public TextView soyIsim ;
public CardView cardView ;
public ViewHolder(View itemView) {
super(itemView);
isim = itemView.findViewById(R.id.textIsım);
soyIsim=itemView.findViewById(R.id.textSoyIsim);
cardView = itemView.findViewById(R.id.cardView);
}
}
List<PlaceHolderModel> placeHolderModel;
public SimpleRecyclerAdapter(List<PlaceHolderModel> placeHolderModel) {
this.placeHolderModel = placeHolderModel;
}
#Override
public SimpleRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_custom,parent,false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder ;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.isim.setText(placeHolderModel.get(position).name);
holder.soyIsim.setText(placeHolderModel.get(position).username);
}
#Override
public int getItemCount() {
return placeHolderModel.size();
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
}
ServiceGenerator.java
public interface ServiceGenerator {
#GET("/users")
Call<List<PlaceHolderModel>> placeHolderModel();
}
Thank you very much !
Your advice important for me!
I have this strage error. I'm downloading data from API and I want to print it in RecyclerView nested in Fragment called ListFragment. This fragment is one of three which I use in ViewPager. ViewPager works fine. For now, I want to display only two textViews. Layout for them has name single_data_layout. List<Feature> features is my DataResponse. Project builds normaly without issues and I receive in Log that "Data is successfully downloaded". When I run app in DebugMode I get message that my RecyclerView isn't attached to adapter. Any ideas?
ApiClient:
public interface ApiClient {
#GET("/query?format=geojson&starttime&minsig=700")
Call<DataResponse> getData();
}
ApiClientFactory:
public class ApiClientFactory {
public static final String baseURL = "https://earthquake.usgs.gov/fdsnws/event/1/";
public ApiClient createApiClient(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseURL)
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit.create(ApiClient.class);
}
}
DataAdapter:
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.DataViewHolder> {
private List<Feature> features;
private ListFragment listFragment;
private Context context;
private LayoutInflater inflater;
public DataAdapter(List<Feature> features) {
this.features = features;
}
#Override
public DataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
inflater = LayoutInflater.from(context);
View contractView = inflater.inflate(R.layout.single_data_layout, parent, false);
return new DataViewHolder(contractView);
}
#Override
public void onBindViewHolder(DataViewHolder holder, int position) {
holder.place.setText(features.get(position).getProperties().getPlace());
holder.alert.setText(features.get(position).getProperties().getAlert());
}
#Override
public int getItemCount() {
return features.size();
}
public static class DataViewHolder extends RecyclerView.ViewHolder {
private final TextView place;
private final TextView alert;
public DataViewHolder(View view) {
super(view);
place = (TextView) view.findViewById(R.id.place_text_view);
alert = (TextView) view.findViewById(R.id.alert_text_view);
}
}
}
ListFragment:
public class ListFragment extends Fragment {
private RecyclerView recyclerView;
private static final String TAG = ListFragment.class.getSimpleName();
private ApiClient apiClient;
private List<Feature> features;
private RecyclerView.LayoutManager layoutManager;
private DataAdapter adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_list, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
getData();
return view;
}
private void getData() {
apiClient = new ApiClientFactory().createApiClient();
apiClient.getData().enqueue(new Callback<DataResponse>() {
#Override
public void onResponse(Call<DataResponse> call, Response<DataResponse> response) {
if (response.isSuccessful()) {
features = response.body().getFeatures();
adapter = new DataAdapter(features);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
}
Log.d(TAG, "Data successfully downloaded");
}
#Override
public void onFailure(Call<DataResponse> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
}
You should change the way you inflate the layout. This should do the trick.
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.DataViewHolder> {
private List<Feature> features;
public DataAdapter(List<Feature> features) {
this.features = features;
}
#Override
public DataAdapter.DataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.single_data_layout, parent, false);
return new DataViewHolder(view);
}
#Override
public void onBindViewHolder(DataViewHolder holder, int position) {
holder.place.setText(features.get(position).getProperties().getPlace());
holder.alert.setText(features.get(position).getProperties().getAlert());
}
#Override
public int getItemCount() {
return features.size();
}
public static class DataViewHolder extends RecyclerView.ViewHolder {
private final TextView place;
private final TextView alert;
public DataViewHolder(View view) {
super(view);
place = (TextView) view.findViewById(R.id.place_text_view);
alert = (TextView) view.findViewById(R.id.alert_text_view);
}
}
}
I see that the adapter class don't have a context , I guess if you add to the adapter constructor Context c as a second parameter your problem will be solved
try to replase
public DataAdapter(List<Feature> features) {
this.features = features;
}
by this
public DataAdapter(List<Feature> features, Context c) {
this.features = features;
this.context = c;
}
and replace this line in the fragment class
adapter = new DataAdapter(features);
by this
adapter = new DataAdapter(features,getActivity());
hope this will help you :)
Please I would like someone to help point me in the right direction with using the ParseRecyclerQueryAdapter. I'm trying to retrieve articles with my current adapter class that implements the standard RecyclerView. my implementation of pagination is not working properly soIi would like a demonstration from anyone that has used the ParseRecyclerQueryAdapter to achieve the following. By translating it from me so I get the implementation.
public class ArticleRVAdapter extends RecyclerView.Adapter {
List<Article> articleData = Collections.emptyList();
private LayoutInflater inflater;
private Context context;
public ArticleRVAdapter(Context context, List<Article> data){
inflater=LayoutInflater.from(context);
this.articleData= data;
this.context = context;
}
#Override
public ArticleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.article_item, parent, false);
ArticleViewHolder viewHolder = new ArticleViewHolder(view);
return viewHolder;
}
#Override
public int getItemCount() {
return articleData.size();
}
public class ArticleViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
CardView cardView;
TextView title;
TextView body;
Date dateCreated;
TextView author;
ImageView headImage;
String objectId;
public ArticleViewHolder(final View itemView) {
super(itemView);
itemView.setClickable(true);
itemView.setLongClickable(true);
itemView.setOnClickListener(this);
cardView = (CardView) itemView.findViewById(R.id.card_article);
title = (TextView) itemView.findViewById(R.id.text_title);
body = (TextView) itemView.findViewById(R.id.text_article_body);
//dateCreated = itemView.findViewById(R.id.text_article_body);
author = (TextView) itemView.findViewById(R.id.text_author);
headImage = (ImageView) itemView.findViewById(R.id.imageView_thumb);
}
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), ArticleInformationActivity.class);
intent.putExtra("article_id", articleData.get(getLayoutPosition()).getObjectId());
intent.putExtra("article_title", articleData.get(getLayoutPosition()).getArticleTitle());
intent.putExtra("article_body", articleData.get(getLayoutPosition()).getArticleBody());
intent.putExtra("article_author", articleData.get(getLayoutPosition()).getArticleAuthor());
intent.putExtra("article_date", articleData.get(getLayoutPosition()).getDateCreated());
v.getContext().startActivity(intent);
}
}
After a lot of testing, I got the solution in my project:
Fragment (or Activity):
private RecyclerView mRecyclerView;
private MyQueryAdapter myQueryAdapter;
private SwipeRefreshLayout swipeRefreshLayout;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list_fragment, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.rv);
myQueryAdapter = new MyQueryAdapter(true);
mRecyclerView.setAdapter(myQueryAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
myQueryAdapter.addOnQueryLoadListener(new ParseRecyclerQueryAdapter.OnQueryLoadListener<MY_MODEL>() {
#Override
public void onLoaded(List<MY_MODEL> objects, Exception e) {
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
}
}
#Override
public void onLoading() {
if (!swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(true);
}
}
});
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
myQueryAdapter.loadObjects();
}
});
return view;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
#Override
public void onResume() {
super.onResume();
myQueryAdapter.loadObjects();
}
Adapter
public class MyQueryAdapter extends ParseRecyclerQueryAdapter<MY_MODEL, MyQueryAdapter.MyViewHolder>{
public MyQueryAdapter(boolean hasStableIds) {
super(MY_MODEL.class, hasStableIds);
}
public MarcacionesAdapter(ParseQueryAdapter.QueryFactory<Marcaciones> factory, boolean hasStableIds) {
super(factory, hasStableIds);
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, parent, false);
MyViewHolder myViewHolder = new MyViewHolder(v);
return myViewHolder;
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
MY_MODEL model = getItem(position);
holder.name.setText(model.getName());
holder.year.setText(model.getYear());
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView name;
TextView year;
MyViewHolder(View itemView) {
super(itemView);
cv = (CardView)itemView.findViewById(R.id.card_view);
name = (TextView)itemView.findViewById(R.id.name);
year = (TextView)itemView.findViewById(R.id.year);
}
}
}
If you want to configure a custom query, you can do it in this way:
factory =
new ParseQueryAdapter.QueryFactory<MY_MODEL>() {
public ParseQuery< MY_MODEL > create() {
ParseQuery<MY_MODEL> query = MY_MODEL.getQuery();
query.include("user");
//Filter by date
query.whereGreaterThan("createdAt", midnight);
query.whereLessThan("createdAt", now);
query.orderByDescending("createdAt");
return query;
}
};
adapter = new MyQueryAdapter(factory, true);