我使用json
从api
获取retrofit
数据,我使用改造教程正确实现了它,但我不知道它为什么不提取数据。
这是我的主要课程:
List<noti_sec> noti_list;
ImageView down_img;
TextView heading_txt;
String sessionId ;
String userId;
Handler handler;
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cinsio_notif);
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.noti_recyle);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
heading_txt =(TextView) findViewById(R.id.heading_txt);
down_img = (ImageView) findViewById(R.id.down_img);
heading_txt.setText("Notifications");
down_img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(CinsioNotif.this, CinsioMain.class);
//startActivity(i);
finish();
overridePendingTransition(R.anim.slide_in_down,R.anim.slide_out_down);
}
});
// recyclerView.setLayoutManager(new LinearLayoutManager(this));
SharedPreferences preferences = getSharedPreferences("USER", MODE_PRIVATE);
sessionId = preferences.getString("session", "");
userId=preferences.getString("id","");
notiIterface apiService =
ApiClient.getClient().create(notiIterface.class);
Call<full_noti_sec> call = apiService.getNotification(userId,"",sessionId);
call.enqueue(new Callback<full_noti_sec>() {
@Override
public void onResponse(Call<full_noti_sec> call, Response<full_noti_sec> response) {
List<noti_sec> notif = response.body().getData();
Log.d(TAG, "Number of notification received: " + notif.size());
recyclerView.setAdapter(new noti_adapter(notif,getApplicationContext(),R.layout.noti_msg_screen));
}
@Override
public void onFailure(Call<full_noti_sec> call, Throwable t) {
}
});
}
我的adpater课程:
List<noti_sec> noti_list;
private Context context;
private int rowLayout;
//Constructor of this class
public noti_adapter(List<noti_sec> noti_list, Context context,int rowLayout){
super();
//Getting all superheroes
this.noti_list = noti_list;
this.context = context;
this.rowLayout = rowLayout;
}
public static class notiViewHolder extends RecyclerView.ViewHolder {
CircleImageView profile_pic;
TextView name;
TextView about_noti;
TextView noti_time;
ImageView from;
public notiViewHolder(View v) {
super(v);
profile_pic = (CircleImageView) v.findViewById(R.id.profile_image);
name = (TextView) v.findViewById(R.id.name);
about_noti = (TextView) v.findViewById(R.id.notif_about);
noti_time = (TextView) v.findViewById(R.id.noti_time);
from = (ImageView) v.findViewById(R.id.msg_img);
}
}
@Override
public noti_adapter.notiViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(rowLayout, parent, false);
return new notiViewHolder(view);
}
@Override
public void onBindViewHolder(notiViewHolder holder, final int position) {
;
SharedPreferences preferences = context.getSharedPreferences("USER", 0);
String fname = preferences.getString("firstname", "");
String lname = preferences.getString("lastname", "");
String uname = preferences.getString("username", "");
String img = preferences.getString("imgname", "");
String id = preferences.getString("id", "");
String image = "http://chikoop.com/api/uploads/" + id + "/" + noti_list.get(position).getImgname();
holder.profile_pic.setImageResource(R.drawable.border_frame1);
holder.name.setText(noti_list.get(position).getUsername());
holder.about_noti.setText(noti_list.get(position).getNoti_msg());
Picasso.with(context)
.load(image)
.into(holder.from);
//holder.from.setImageResource(noti_list.get(position).getFor_image());
}
@Override
public int getItemCount() {
return noti_list.size();
}
我的界面类:
public interface notiIterface {
@GET("user/get_notifications")
Call<full_noti_sec> getNotification(@Query("userid") String userid,@Query("notification_id") String notiid, @Query("session") String apiKey);
}
我尝试了一切,但我的布局没有显示任何内容。会话和userID都是正确的。高级中的Thanxx