2012-04-30 3 views
1

배열 목록 항목 [x, y, z ...]을 맞춤 어댑터에 보냅니다. listview에 항목을 표시하고 싶습니다. 난 itemNames에를 pritem 수 측의 getView 방법 .IN 루프 (X, Y, Z ... 등)에 사용하는 모든 항목을 인쇄 할 수있다 [possition는] ...는 배열리스트를 인쇄 할 수 없다는 것을 의미 내가 다android의 맞춤 목록보기에 항목 이름을 표시 할 수 없습니다.

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; 
    } 
} 

실수하십시오 ...

답변

0

arraylist sizegetCount() 대신 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; 
     } 
} 
관련 문제