1

カスタム アダプターに配列リスト項目 [x、y、z...] を送信しています。リストビューでアイテムを表示したい。for loop(x,y,z...like) を使用してすべての項目を印刷できます。側の getview メソッドで、itemnames[possition] を優先できます。これは、配列リストを印刷できないことを意味します ...

    i try this code
     public class CustomAdapter extends BaseAdapter{
public static ArrayList<String> arr=new ArrayList<String>();
public Context Context;

  private LayoutInflater inflater;



  HashMap<String, String> map = new HashMap<String, String>();
 public CustomAdapter(Context context, ArrayList<String> arr) {
     Context=context;
        //inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //  imageLoader=new ImageLoader(activity);
        inflater=LayoutInflater.from(context);

     arr=arr;
    for(int i=0;i<arr.size();i++)
    {
       arr.get(i);

    }
 }
public int getCount() {
    // TODO Auto-generated method stub
    return arr.size();
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}
  public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub

View vi=convertView;
vi=inflater.inflate(R.layout.selecteditemlistview, null);
System.out.println(arr.get(position));
TextView text=(TextView)vi.findViewById(R.id.selectedtext);
text.setText(arr.get(position));
return vi;
  }
 }

どこで間違えたのか教えてください...

4

1 に答える 1

0

arraylist sizeの代わりにgetCount()Method で返す必要がありreturn 0ます。

public class CustomAdapter extends BaseAdapter
{
    public static ArrayList<String> arr=new ArrayList<String>();
    public Context Context;
    private LayoutInflater inflater;

    HashMap<String, String> map = new HashMap<String, String>();
    public CustomAdapter(Context context, ArrayList<String> arr) 
    {
        Context=context;
        inflater=LayoutInflater.from(context);
        arrr=arr;
    }
    public int getCount() 
    {
        // TODO Auto-generated method stub
        return arr.size();
    }

    public Object getItem(int position) 
    {
        // TODO Auto-generated method stub
        return arr.get(position);
    }

    public long getItemId(int position) 
    {
        // TODO Auto-generated method stub
        return position;
    }

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

            if (convertView == null) 
            {
                convertView = mInflater.inflate(R.layout.selecteditemlistview, null);
                holder = new ViewHolder();

                holder.textViewSelectedText = (TextView)convertView.findViewById(R.id.selectedtext);
                convertView.setTag(holder);
            }
            else 
            {
                holder = (ViewHolder) convertView.getTag();
            }

            holder.textViewSelectedText.setText(arr.get(position));
            return convertView;
        }

        class ViewHolder
        {
            TextView textViewSelectedText = null;
        }
 }
于 2012-04-30T07:35:37.843 に答える