如何在android中显示最后一个组名

时间:2015-02-12 05:52:57

标签: android

你好在下面的截图中显示用户的所有朋友,这些朋友是user3,user1,user11。新的是groupname现在,我的问题是它在friendsname之后显示groupname三次。但是我只想要一次性显示groupname。我想显示像这个user3,user1,user11和New我希望显示的完全像这样1。关闭此活动后,如果我打开相同的活动意味着groupname不显示它只显示朋友的名字

但我希望在关闭此活动时,Groupname应显示为常量。

这是我的代码 样品scrren拍摄:

user3
New
_________
user1
New
______
user11
New

FriendList.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;

    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.text1=(TextView)convertView.findViewById(R.id.text1);
                holder.text = (TextView) convertView.findViewById(R.id.text);

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

                convertView.setTag(holder);
            }   
            else {

                holder = (ViewHolder) convertView.getTag();

            }


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



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

            return convertView;
        }

    }

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView android:id="@+id/icon"
        android:layout_width="48dip"
        android:layout_height="48dip" />

    <TextView android:id="@+id/text"
        android:layout_gravity="center_vertical"
        android:layout_width="0dip"
        android:layout_weight="1.0"
        android:layout_height="wrap_content" />




</LinearLayout>
 <LinearLayout
        android:orientation="horizontal"

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
  <TextView android:id="@+id/text1"
        android:layout_gravity="center_vertical"
        android:layout_width="0dip"
        android:layout_weight="1.0"
        android:layout_height="wrap_content" />
  </LinearLayout>
   </LinearLayout>

0 个答案:

没有答案