我无法在自定义列表类中使用display:inline-block
变量。它说“表达
预期”。如何在自定义列表类中使用它?我正在使用 Retrofit 从服务器获取JSON:
user
我在call.enqueue(new Callback<List<Hero>>() {
@Override
public void onResponse(Call<List<Hero>> call, Response<List<Hero>> response) {
final List<Hero> heroes = response.body();
final String[] user = new String[heroes.size()];
int userInt = heroes.size();
for (int i = 0; i < heroes.size(); i++) {
user[i] = heroes.get(i).getUsername();
}
customList cl = new customList();
l1.setAdapter(cl);
}
@Override
public void onFailure(Call<List<Hero>> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_LONG).show();
}
});
class customList extends BaseAdapter {
@Override
public int getCount() {
return user.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@SuppressLint({"ViewHolder", "InflateParams"})
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = getLayoutInflater().inflate(R.layout.activity_list,null);
ImageView img = view.findViewById(R.id.img1);
TextView txt = view.findViewById(R.id.t1);
txt.setText(user[i]);
return null;
}
}
中创建了user
变量,现在我只想在自定义列表视图中显示它(服务器数据),但是当我移动{{ 1}}变量添加到类中。