2014-09-20 105 views
1

我有這個類延伸BaseAdapter我用來插入icon併爲listView的每一行就是一個抽屜getView不叫上baseAdapter類

public class NavRightDrawerListAdapter extends BaseAdapter { 

    private Context context; 
    LinkedList<String> userNameUsedForListView; 
    Map<String, Bitmap> urlUserImage; 

    public NavRightDrawerListAdapter(Context context, LinkedList<String> userNameUsedForListView, Map<String, Bitmap> returnBitMapFromURL) { 
     this.context = context; 
     this.userNameUsedForListView = userNameUsedForListView; 
     this.urlUserImage = returnBitMapFromURL; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     int count = 0; 
     if (convertView == null) { 
      LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
      convertView = mInflater.inflate(R.layout.drawer_list_of_action, null); 
     } 

     ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon); 
     TextView txtTitle = (TextView) convertView.findViewById(R.id.title); 

     imgIcon.setImageBitmap(urlUserImage.get(userNameUsedForListView.get(count))); 
     txtTitle.setText(userNameUsedForListView.get(count)); 
     count++; 
     return convertView; 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

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

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

內,在我的活動我做了textView這個:

[...] 
rightDrawerLinearLayout = (LinearLayout) findViewById(R.id.right_drawer_ll); 
rightDrawerListForFollow = (ListView) findViewById(R.id.right_drawer); 
NavRightDrawerListAdapter adapter = new NavRightDrawerListAdapter(getApplicationContext(), userNameUsedForListView,returnBitMapFromURL); 
rightDrawerListForFollow.setAdapter(adapter); 
[...] 

我注意到getView沒有被調用,有人可以解釋我爲什麼?

非常感謝。

+0

我猜測由於你的適配器聲稱是空的(getCount返回0),ListView並不打擾要求項目視圖 – 2014-09-20 16:32:01

+0

好吧,我必須返回適配器使用的lsit的大小?我不能把它留到0? – 2014-09-20 16:42:51

回答

6

在你的方法

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return 0; 
} 

你是返回0。所以你的方法不叫。而是在getCount方法中返回列表視圖的大小。

+0

謝謝你的回答,先調用getCount吧?和getView? – 2014-09-20 16:45:24

+1

是的,首先調用getCount()方法,然後在返回計數器值時多次調用getView()。 – Beena 2014-09-20 16:47:58