1

Hi in the below code how to find the last position of the friends[position].userName and then how to compare it and based on the position how to set the text for holder.text1.

For example friends[position] it reaches the last positions means then upto some position friends[position].userName values are there.Now next position I want to occupy this holder.text1.setText(groupdetails); value
Can any one help me

java

public class FriendList extends ListActivity 
{
    private static final int ADD_NEW_FRIEND_ID = Menu.FIRST;
    private static final int CREATE_GROUP_ID = Menu.FIRST+1;
    private static final int EXIT_APP_ID = Menu.FIRST + 2;
    private IAppManager imService = null;
    private FriendListAdapter friendAdapter;
    String groupdetails;
    public String ownusername = new String();

    private class FriendListAdapter extends BaseAdapter 
    {       
        class ViewHolder {
            TextView text,text1;

            ImageView icon;
        }
        private LayoutInflater mInflater;
        private Bitmap mOnlineIcon;
        private Bitmap mOfflineIcon;        

        private FriendInfo[] friends = null;


        public FriendListAdapter(Context context) {
            super();            

            mInflater = LayoutInflater.from(context);

            mOnlineIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.greenstar);
            mOfflineIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.redstar);

        }

        public void setFriendList(FriendInfo[] friends)
        {
            this.friends = friends;
            }


        public int getCount() {     

            return friends.length;
        }


        public FriendInfo getItem(int position) {           

            return friends[position];
        }

        public long getItemId(int position) {

            return 0;
        }

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

            ViewHolder holder;


            if (convertView == null) 
            {
                convertView = mInflater.inflate(R.layout.friend_list_screen,null);


                holder = new ViewHolder();

                holder.text = (TextView) convertView.findViewById(R.id.text);
                holder.text1 = (TextView) convertView.findViewById(R.id.text1);

                holder.icon = (ImageView) convertView.findViewById(R.id.icon);                                       

                convertView.setTag(holder);
            }   
            else {

                holder = (ViewHolder) convertView.getTag();

            }

            holder.text.setText(friends[position].userName);


            if((friends[position]).userName.length()>18)
            {
                holder.text1.setVisibility(View.VISIBLE);
                holder.text1.setText(groupdetails);
            }

            holder.icon.setImageBitmap(friends[position].status == STATUS.ONLINE ? mOnlineIcon : mOfflineIcon);


            return convertView;
        }

    }
tagore
  • 13
  • 6
  • to which value want to compare last position value ? – ρяσѕρєя K Feb 13 '15 at 11:06
  • Can you elaborate your question? Right now it seems difficult to understand the question properly. – BBdev Feb 13 '15 at 11:08
  • @ρяσѕρєяK friends[position] value I want to compare this value.suppose this is equal to last position means I want to set the text to next postion – tagore Feb 13 '15 at 11:09
  • @ρяσѕρєяK friends[position].username these values are 1st position having the value user1 and 2nd position having the value user3 and third postion having the value user11.Now next does not contains any value position of the next value 4.Now I want to check the position if it contains the any friends[position].username if it not there means 4th postion must be the value of this holder.text1.setText(groupdetails); – tagore Feb 13 '15 at 11:16
  • @ρяσѕρєяK did you got it or not – tagore Feb 13 '15 at 11:26

1 Answers1

0

getView method only show rows in list according to number of count return from getCount method .

So i'm considering you are creating class constructor in which extending some Adapter. add one more dummy item in ArrayList and currently using Array use Arraylist:

 ArrayList<FriendInfo> listFriends;
public void setFriendList(FriendInfo[] friends)
  {
        this.listFriends=new ArrayList<FriendInfo>(Arrays.asList(friends));
        FriendInfo objectGroup=new FriendInfo();
        objectGroup.userName=groupdetails;
        listFriends.add(objectGroup);
  }

Now use listFriends instead of friends in Adapter like in getCount(),getItem methods. ListView will show groupdetails in last row of ListView.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • @tagore: Dear i hope you know how to get values,size from ArrayList? use `return listFriends.size();` instead of `return friends.length;` – ρяσѕρєя K Feb 13 '15 at 12:13
  • @tagore: and `return listFriends.get(position);` from `getItem` so same on other lines where using `friends[position]` – ρяσѕρєя K Feb 13 '15 at 12:15
  • @tagore: then are you able to run application? – ρяσѕρєя K Feb 13 '15 at 12:15
  • @tagore: yes ask me please – ρяσѕρєя K Feb 13 '15 at 12:28
  • NewGroup is the two groupnames how to display separtly in listview – tagore Feb 13 '15 at 12:31
  • @tagore: in `setFriendList` as we are adding `groupdetails` do it in same way – ρяσѕρєя K Feb 13 '15 at 12:31
  • one user he can create the n no. of group is it? Now,I am returning string if i want to return more than one value I want to return as array is it? or any way is there – tagore Feb 13 '15 at 12:35
  • @tagore: Yes return ArrayList instead of Array because search,add,remove is easy in ArrayList as compare to Array – ρяσѕρєя K Feb 13 '15 at 12:41
  • String groupdetails = imService.DispalyGroupDetails(imService.getUsername()); for here I am getting the result from from the server these one if I want to convert these String to arraylist means problem got solved r not? – tagore Feb 13 '15 at 12:46
  • small doubt suppose based on username your displaying groupdetails suppose one more groupname i want to display means based on position I want to display but your giving code based on username – tagore Feb 16 '15 at 05:22