gpt4 book ai didi

android - API 应以 JSON 格式返回数据,但不显示在布局中

转载 作者:行者123 更新时间:2023-11-29 02:18:15 25 4
gpt4 key购买 nike

我正在尝试将我的 json 响应传递给适配器类,我正在从其余 api 获得响应,但在改造处理程序类将 json 响应转换为对象数组后,json 对象数组仍然没有传递给适配器类。我没有收到任何日志错误或警告,但是当我尝试在我的 Android 应用程序中使用此 Activity 时,我没有收到任何结果。

public class HistoryActivity extends AppBaseActivity {

@BindView(R.id.history_header)
RelativeLayout history_header;

@BindView(R.id.history_list)
ListView history_list;

@BindView(R.id.no_history_view)
LinearLayout no_history_view;

@BindView(R.id.hdr_back)
TextView hdr_back;

private String address;
private String category;
private String distance;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);

unbinder= ButterKnife.bind(this);
backBtnSet();

updateHeader();
Intent intent=getIntent();

if(intent!=null && intent.hasExtra("mid")){
String mId=intent.getStringExtra("mid");

address=intent.getStringExtra("address");
category=intent.getStringExtra("category");
distance=intent.getStringExtra("distance");

fetchHistory(mId);
}else {
activityFinish();
}
}

private void backBtnSet() {

final int height= (int) getResources().getDimension(R.dimen.dp_24);
hdr_back.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Drawable img = getBaseContext().getResources().getDrawable(
R.drawable.ic_backarrow);
img.setBounds(0, 0, height,
height);
hdr_back.setCompoundDrawables(img, null, null, null);
hdr_back.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

private void updateHeader() {
TextView hView= history_header.findViewById(R.id.hdr_title);
hView.setText(getString(R.string.history_small));
}

private void fetchHistory(String mId) {
JsonObject jObject=ParamConvertor.getCustomerHistory(userInfo.getId(),
userInfo.getAccessKey(),mId);

Call<ArrayList<HistoryCustomer>> call=apiService.getCustomerHistory(jObject);
call.enqueue(new RetrofitHandlerFull<ArrayList<HistoryCustomer>>(this,
networkHandler,1));
AppLogger.printPostBodyCall(call);
}
//Problem persists from here
private INetworkHandler<ArrayList<HistoryCustomer>> networkHandler
= new INetworkHandler<ArrayList<HistoryCustomer>>() {

@Override
public void onResponse(ArrayList<HistoryCustomer> data, String msg, int num) {
if(data!=null && !data.isEmpty()){
updateList(data);
dataPresent(true);

}else{
dataPresent(false);
}
}

@Override
public void onFailure(String msg, int error) {
dataPresent(false);
}
};

private void updateList(ArrayList<HistoryCustomer> data){
HistoryAdapter adapter=new HistoryAdapter(this,data,
address,category);

history_list.setAdapter(adapter);
}


private void dataPresent(boolean isPresent){
if(isPresent){
no_history_view.setVisibility(View.GONE);
history_list.setVisibility(View.VISIBLE);
}else{
no_history_view.setVisibility(View.VISIBLE);
history_list.setVisibility(View.GONE);
}
}


@OnClick(R.id.hdr_back)
void onCLicks(View view){

switch (view.getId()){

case R.id.hdr_back:
activityFinish();
break;
}
}
}

最佳答案

根据您的代码,我觉得您可以检查您正在调用的端点是否可能返回 null 或空对象。

关于android - API 应以 JSON 格式返回数据,但不显示在布局中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58715357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com