我正在尝试基于一些示例创建自定义适配器,但我不断收到一些我无法解决的错误。
我将发布完整的课程,然后我会指出错误。
package br.com.agenciaeisberg.qm;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Created by Usuário on 04/02/2015.
*/
public class HospitaisAdapter extends BaseAdapter {
private ArrayList<Hospitais> ListaHospitais;
private Context context;
private LayoutInflater layoutInflater;
public HospitaisAdapter (Context context, ArrayList<Hospitais> ListaHospitais) {
this.ListaHospitais= ListaHospitais;
this.context=context;
layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return listData.size();
}
@Override
public Object getItem(int position) {
return listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.item_hospital, null);
holder = new ViewHolder();
holder.pid= (TextView) convertView.findViewById(R.id.pid);
holder.nome= (TextView) convertView.findViewById(R.id.nome);
holder.image= (ImageView) convertView.findViewById(R.id.imglotacao);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Hospitais item = (Hospitais) ListaHospitais.get(position);
holder.pid.setText(item.getPid());
holder.nome.setText(item.getNome());
holder.image.setImageDrawable(context.getResources().getDrawable(R.drawable.l_9_1));
return convertView;
}
static class ViewHolder {
TextView pid;
TextView nome;
ImageView image;
}
}
至于错误
1 - 它表示无法解析此符号:
private ArrayList<Hospitais> ListaHospitais;
private Context context;
private LayoutInflater layoutInflater;
public HospitaisAdapter (Context context, ArrayList<Hospitais> ListaHospitais) {
this.ListaHospitais= ListaHospitais;
this.context=context;
layoutInflater = LayoutInflater.from(context);
}
我无法理解发生了什么。
2 - 无法解析符号listData
@Override
public int getCount() {
return listData.size();
}
@Override
public Object getItem(int position) {
return listData.get(position);
}
3 - 无法解析此getPid和getNome的方法
holder.pid.setText(item.getPid());
holder.nome.setText(item.getNome());
答案 0 :(得分:1)
在getCount()
和getItem()
替换
listData
带
ListaHospitais
检查班级Hospitais
是否有方法getPid()
和getNome()
答案 1 :(得分:0)
从我所看到的情况来看,listData
永远不会在任何地方定义,因此&#34;无法解析符号listData&#34;