0

配列リストがあり、アダプタクラスで使用しました。すべてがうまくいきましたが、配列リストから特定のインデックスを削除すると(私の場合data)、配列リストのサイズはゼロになります。

これが私のAdapterクラスです

public class MainLocalListAdapter extends BaseAdapter{
public static final int LIMIT_LIST_COUNT = 20;
private Activity activity;
private static ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
private int count = LIMIT_LIST_COUNT;
private int customPosition = 0;

public MainLocalListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data = d;
    if(count > data.size()) count = data.size();

    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
    return count;//data.size();
}

public Object getItem(int position) {
    return position;
}

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


public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    if(convertView==null){
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.playlist_local_item, null);
        holder.textView = (TextView)convertView.findViewById(R.id.waveTitle2); // title
        holder.textView.setTypeface(UtiliShare.getTf());

        holder.btnCancel = (ImageView) convertView.findViewById(R.id.btndel);
        holder.btnCancel.setOnClickListener(mOnClickListener);  

        convertView.setTag(holder);
    }else{
         holder = (ViewHolder)convertView.getTag();
    }
    if(!data.isEmpty()) {
        HashMap<String, String> song = data.get(position);
        holder.btnCancel.setTag(position);
        holder.textView.setText(song.get(UtiliShare.KEY_TITLE));
    }

    return convertView;
}

private static class ViewHolder{
    TextView textView;
    ImageView btnCancel;
}

private OnClickListener mOnClickListener = new OnClickListener() {

    @Override
    public void onClick(View v) {
        Toast.makeText(MainLocalListAdapter.this.activity, ""+v.getTag(), Toast.LENGTH_SHORT).show();

        data.remove((Integer) v.getTag());

        // Here data.size = 0 ????????????
        int nval = data.size();
        Log.d("list", ""+nval);
        notifyDataSetChanged();
    }
};

public int getCustomPosition() {
    return customPosition;
}

public void setCustomPosition(int cPosition) {
    customPosition = cPosition;

    int nval = (data.size() - customPosition); 
    if(nval < LIMIT_LIST_COUNT) this.count = nval;
    else  count = LIMIT_LIST_COUNT;
}


}

でデータを取得する前にデータサイズを確認するため、エラーは発生しませんgetView()

どうすればこれを修正できますか?

4

0 に答える 0