0

嗨,我试图listview从 a中填充 abaseadapter并且当在 alistview上选择错误时id会传播。

这是我的适配器

public class MyCustomBaseAdapter extends BaseAdapter {
    private static ArrayList<Custom> AList;

    private LayoutInflater inflat;

    public MyCustomBaseAdapter(Context context, ArrayList<Custom> results) {
        AList = results;
        inflat = LayoutInflater.from(context);
    }

    public int getCount() {
        return AList.size();
    }

    public Object getItem(int position) {
        return AList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflat.inflate(R.layout.suspect_list, null);
            holder = new ViewHolder();
            holder.txtName = (TextView) convertView.findViewById(R.id.suspect_name);
            holder.txtSex = (TextView) convertView.findViewById(R.id.suspect_sex);
            holder.txtId = (TextView) convertView.findViewById(R.id.suspect_id);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.txtName.setText(AList.get(position).getName());
        holder.txtSex.setText(AList.get(position).getSex());
        holder.txtId.setText(AList.get(position).getID());

        return convertView;
    }

    static class ViewHolder {
        TextView txtName;
        TextView txtSex;
        TextView txtId;
    }

}

您可以提供的任何帮助都会很棒 可根据要求提供更多代码

4

1 回答 1

0

您的 getItemId() 应该返回 id。所以应该是这样->

public long getItemId(int position) {
        return AList.get(position).getID();
    }

假设 ID 很长,如果不是,则使用 ->Long.parseLong(AList.get(position).getID());

于 2013-05-05T21:59:19.953 回答