0

私はArrayAdapter満たされてArrayListいます。その項目のいずれかをクリックするたびに、 に再入力してArrayListに送信notifyOnDataSetChange()adapterます。しかし、理由は不明ですが、項目を設定する方法ではArrayList範囲外になります。getView()なぜこれが起こるのかわかりません。呼び出しの理論を説明していただけないでしょgetView()うか。なぜこれが起こっているのか理解できます。前もって感謝します!

ここにあります:

class MAdapter extends ArrayAdapter<String> {
    public MAdapter(Context context, int textViewResourceId, List<String> objects) {
        super(context, textViewResourceId, objects);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater vi = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.file_explorer_row, null);
    } else {

    }

        String txt = itemsList.get(position); // Out of bounds happens here
        if (!txt.equals("")) {
            TextView tt = (TextView) v.findViewById(R.id.file_explorer_tv_filename);
            tt.setText(txt);
        }

    return v;
}

itemsListOuter Class で宣言されています。

4

4 に答える 4

1

このように変化する

public View getView(int position, View convertView, ViewGroup parent) {         
        View view = convertView;
        if (view == null) 
        {              
            LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);          
            view = inflater.inflate(R.layout.file_explorer_row, parent, false);
        }       
于 2012-07-07T12:05:39.350 に答える
0

String txt = itemsList.get(position);
itemsList.get(position)整数値を返し、文字列に格納しようとしていることを返します。これが理由である可能性があります。

于 2012-07-07T11:52:30.067 に答える
0

私はあなたが何を求めているのかはっきりとはわかりませんが..私はそれを想定していますが、あなたは再びArrayAdapter全体を補充しています...

だからこれを試してみてください.........

アダプターを設定する前に、ListViewでremoveView()を使用してください...

例えば:

ListView.removeView(); 
ListView.setAdapter(yourAdapter);
于 2012-07-07T12:01:58.673 に答える
0

このコードを試してください:

class MAdapter extends BaseAdapter {
    List<String> objects;
    Context context;
    public MAdapter(Context context,List<String> objects) {
        super();
        this.context=context;
        this.objects=objects;
    }



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

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    Holder holder;
    LayoutInflater vi;
    if (v == null) {
        holder=new Holder();
        vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.file_explorer_row, null);
        holder.tt= (TextView) v.findViewById(R.id.file_explorer_tv_filename);
        v.setTag(holder);
    } else {
        holder = (Holder) v.getTag();
    }
        String txt = objects.get(position); // Out of bounds happens here
        if (!txt.equals("")) {
            holder.tt.setText(txt);
        }

    return v;
}

static class Holder{
    TextView tt;
}
}
于 2012-07-07T12:10:04.187 に答える