I am trying to build a news app where once the user clicks on a news item, it will open the news in another activity in details. But currently, I am having a problem trying to open an activity once the user clicks on any of the news items.
I am using a recycler view to parse the response I get from the JSON using volley for the internet connection, I have tried some of the examples already stated in StackOverflow but non seems to be working to my expectation.
@Override
public void onBindViewHolder(@NonNull final newsAdapter.viewHolder viewHolder, int i) {
dataModel dataModel = mDataModel.get(i);
viewHolder.mTextView.setText(dataModel.getTitle());
viewHolder.mTextDescrip.setText(dataModel.getDescrip());
Glide.with(context).load(dataModel.getImage()).into(viewHolder.mImageView);
viewHolder.mclickListener.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(new Intent(context, newsActivity.class));
}
});
}
public viewHolder(@NonNull View itemView) {
super(itemView);
mTextView = itemView.findViewById(R.id.layout_text);
mImageView = itemView.findViewById(R.id.layout_image);
mTextDescrip = itemView.findViewById(R.id.layout_descrip);
mclickListener = (CardView) itemView.findViewById(R.id.recyclerviewlayout);
}
I tried adding a setOnClickListener with a toast messages to display a message when the user clicks on an item; it shows the message but when I tried using intent to open another activity the app keeps crashing.
I'm not using an emulator to run this app so I can't get the exact error message that causes the app to crash.