我收到一条错误消息,说没有连接适配器;跳过布局,我几乎在互联网上看到了所有答案,但没有任何解决方案。
这是我的MainActivity
public class DetailArrivalActivity extends AppCompatActivity {
String codeCity, fno;
static Detail arrList;
static Context mContext;
static ApiInterface mApiInterface;
private static RecyclerView.Adapter mAdapter;
private static RecyclerView mRecyclerView;
private static RecyclerView.LayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_arrival);
ButterKnife.bind(this);
mContext = this;
mRecyclerView = findViewById(R.id.recyclerViewV);
mRecyclerView.setHasFixedSize(true);
mApiInterface = ApiClient.getClient().create(ApiInterface.class);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
final Bundle i = new Bundle();
i.putString("city", "KNO"); // Key1
open(i);
}
private void open(Bundle args) {
String city = args.getString("city");
String date = args.getString("flightdate");
String fno = args.getString("flightno");
DetailArrivalActivity.getCity(city, date, fno);
}
public static void getCity(String s, String date, String fno) {
DateFormat df = new SimpleDateFormat("yyyy-MM-d");
date = df.format(Calendar.getInstance().getTime());
Call<DetailModel> arrCall = mApiInterface.getDetailDept("KNO", "2019-02-27", "3K0283");
arrCall.enqueue(new Callback<DetailModel>() {
@Override
public void onResponse(Call<DetailModel> call, Response<DetailModel>
response) {
System.out.println("status code "+response.code());
arrList = response.body().getResult();
mAdapter = new DetailAdapter(arrList, mContext);
mRecyclerView.setAdapter(mAdapter);
}
@Override
public void onFailure(Call<DetailModel> call, Throwable t) {
Log.e("Retrofit Get", t.toString());
}
});
}
}
我的适配器
public class DetailAdapter extends RecyclerView.Adapter<DetailAdapter.DetailViewHolder> {
Detail mDetailList;
private Context mCtx;
public DetailAdapter(Detail arrList, Context mCtx) {
this.mDetailList = arrList;
this.mCtx = mCtx;
}
@Override
public DetailAdapter.DetailViewHolder onCreateViewHolder (ViewGroup parent, int viewType){
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.detail_item, parent, false);
DetailAdapter.DetailViewHolder mViewHolder = new DetailAdapter.DetailViewHolder(mView);
return mViewHolder;
}
@Override
public void onBindViewHolder (final DetailAdapter.DetailViewHolder holder, final int position){
holder.setIsRecyclable(false);
holder.tvFlightNo.setText(mDetailList.getFlightno());
holder.tvSDeparture.setText(mDetailList.getStd());
holder.tvADeparture.setText(mDetailList.getAtd());
}
@Override
public int getItemCount () {
return 1;
}
public class DetailViewHolder extends RecyclerView.ViewHolder{
@BindView(R.id.tvFlightNo)
TextView tvFlightNo;
@BindView(R.id.tvSDeparture)
TextView tvSDeparture;
@BindView(R.id.tvADeparture)
TextView tvADeparture;
public DetailViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
}
当我运行它时,logcat中会显示结果[D / OkHttp:{“ result”:[{“ flightno”:“ 3K0283”,“ reg_aircraft”:“ 9V-JSV”,“ dept”:“ SIN“,” arr“:” KNO“,” std“:” 15:15“,” sta“:” 15:45“,” atd“:” 2019-02-27 15:36:29“,” ata “:” 15:42“,” etdf“:”“,” etaf“:” 2019-02-27 15:34:06“,” etdx“:空,” etax“:” 16:06“,”配对“:”,“ status_flight”:“降落”,“ airport_name_arr”:“新加坡樟宜机场”}],“ status_code”:200}]
所以我认为改造没有问题