Search code examples
androidandroid-listviewposition

how does the position work in the getView in the adapter?


As far as I know, the position returns specific chosen item from the whole list. So how does the adapter use the position and transfers all of the items without some kind of loop? I guess there is a basic mistake in my sight regarding lists and positions. This is the code:

(THANK YOU IN ADVANCE):

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

if (convertView==null){

    convertView= LayoutInflater.from(mContext).inflate(R.layout.customupdatestatus, null);
    holder=new viewHolder();
    holder.statusHomePage=(TextView)convertView.findViewById(R.id.statusUploaded);
    holder.userNameHomePage=(TextView)convertView.findViewById(R.id.userNameUpdate);

    convertView.setTag(holder);
}else{
    holder=(viewHolder) convertView.getTag();
}
        ParseObject statusObject= mStatus.get(position);

String username= statusObject.getString("userName");
        holder.userNameHomePage.setText(username);

        String status=statusObject.getString("newStatus");
        holder.statusHomePage.setText(status);

        return convertView;
    }

Solution

  • Ok, this is something that was bugging me for some time. So, when the view is created, you can see certain amount of rows. From row one to the last row in the view, adapter is counting. When you scroll down, the counter resets, or, I would say, it starts again. So, lets say you have 10 rows on screen when view is created. When you scroll down, if you select to check row number 5, it will select on the first view, when you scroll, it will show the other element is checked too. I tried to find solution to this, but couldn't.