单击用户时将打开用户相册。用户的网站http://jsonplaceholder.typicode.com/users和相册的网站http://jsonplaceholder.typicode.com/albums。我想使用来自MainActivity
的意图Main2Activity
,但我有错误,我上传了下面的图片。
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;
Context context ;
public SimpleRecyclerAdapter(List<PlaceHolderModel> placeHolderModel, Context context) {
this.placeHolderModel = placeHolderModel;
this.context=context;
}
@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, final int position) {
holder.isim.setText(placeHolderModel.get(position).name);
holder.soyIsim.setText(placeHolderModel.get(position).username);
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//what shall i write
Intent intent=new Intent(context,Main2Activity.class);
intent.putExtra("mesaj",placeHolderModel.get(position).id);
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return placeHolderModel.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
}
Main2Activity.java
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent intent =getIntent();
Toast.makeText(this, String.valueOf(intent.getIntExtra("mesaj", 0)), Toast.LENGTH_SHORT).show();
Factory.getInstance().placeAlbums(intent.getIntExtra("mesaj", 0)).enqueue(new Callback<List<PlaceHolderModel>>() {
@Override
public void onResponse(Call<List<PlaceHolderModel>> call, Response<List<PlaceHolderModel>> response) {
}
@Override
public void onFailure(Call<List<PlaceHolderModel>> call, Throwable t) {
}
});
}
}
ServiceGenerator.java
public interface ServiceGenerator {
@GET("/users")
Call<List<PlaceHolderModel>> placeHolderModel();
@GET("/albums")
Call<List<PlaceHolderModel>> placeAlbums(@Query("userId") int userId);
}
您的建议对我很重要
非常感谢!