BaseAdapter position issue(only 0-4)

108 Views Asked by At

I'm trying to make my own custom adapter but I have some problems with position. After running this code I have odd output. In my list I have 30 elements but I got position only from 0 to 4 and elements count that is printed is 15 instead of 30. What is wrong with this code? I checked everything!

So I showed where I have this issue

Log.d(TAG,String.valueOf(position)); //0,1,2,3,4,0,1,2,3,4....0,1,2,3,4
Log.d(TAG, String.valueOf(gitRepositoryItemList.size())); //30 elements

like this. First line give me 15 outputs with values from 0 to 4. Second output gives me 30 as a result. WTF!?!?!?! Here is the code:

public class GitCustomAdapter extends BaseAdapter{

    public static final String TAG = GitCustomAdapter.class.getSimpleName();
    private LayoutInflater inflater;
    private List<GitRepositoryItem> gitRepositoryItemList;
    //ImageLoader imageLoader = VolleySingleton.getInstance(mContext).getImageLoader();

    public GitCustomAdapter(Context mContext, List<GitRepositoryItem> gitRepositoryItemsList) {
        this.gitRepositoryItemList = gitRepositoryItemsList;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return gitRepositoryItemList.size();
    }

    @Override
    public GitRepositoryItem getItem(int position) {
        return gitRepositoryItemList.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
        //this method executes 15 times only while it should be executed 30 times
        if (convertView == null){
            convertView = inflater.inflate(R.layout.list_item,null);
        }
        Log.d(TAG,String.valueOf(position)); //0,1,2,3,4,0,1,2,3,4....0,1,2,3,4
        Log.d(TAG, String.valueOf(gitRepositoryItemList.size())); //30 elements
        return convertView;
    }
}

Also, you can check my output here:

http://pastebin.com/BHAvtA38

0

There are 0 best solutions below