如何在 android 中显示前一个 activity 中的下一个 activity 字符串

how to display the next activity string in previous activity in android

您好,在下面,我会根据用户登录到此应用程序,使用带有在线或离线图像的列表视图显示好友列表。 现在,以同样的方式,我想使用菜单显示 groupname.But 我正在创建新组,即下一个 activity。 但是组名我想在这里显示 friendlist.java class 我正在创建的组应该显示组名和用户的朋友。

好友列表

    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.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);
            holder.icon.setImageBitmap(friends[position].status == STATUS.ONLINE ? mOnlineIcon : mOfflineIcon);

            return convertView;
        }

    }

    public class MessageReceiver extends  BroadcastReceiver  {

        @Override
        public void onReceive(Context context, Intent intent) {

            Log.i("Broadcast receiver ", "received a message");
            Bundle extra = intent.getExtras();
            if (extra != null)
            {
                String action = intent.getAction();
                if (action.equals(IMService.FRIEND_LIST_UPDATED))
                {

                    FriendList.this.updateData(FriendController.getFriendsInfo(), 
                                                FriendController.getUnapprovedFriendsInfo());

                }
            }
        }

    };
    public MessageReceiver messageReceiver = new MessageReceiver();

    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {          
            imService = ((IMService.IMBinder)service).getService();      

            FriendInfo[] friends = FriendController.getFriendsInfo(); 
            if (friends != null) {              
                FriendList.this.updateData(friends, null); 
            }    

            setTitle(imService.getUsername() + "'s friend list");
            ownusername = imService.getUsername();
        }
        public void onServiceDisconnected(ComponentName className) {          
            imService = null;
            Toast.makeText(FriendList.this, R.string.local_service_stopped,
                    Toast.LENGTH_SHORT).show();
        }
    };



    protected void onCreate(Bundle savedInstanceState) 
    {       
        super.onCreate(savedInstanceState);

        setContentView(R.layout.list_screen);

        friendAdapter = new FriendListAdapter(this);





    }
    public void updateData(FriendInfo[] friends, FriendInfo[] unApprovedFriends)
    {
        if (friends != null) {
            friendAdapter.setFriendList(friends);   
            setListAdapter(friendAdapter);              
        }               

        if (unApprovedFriends != null) 
        {
            NotificationManager NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

            if (unApprovedFriends.length > 0)
            {                   
                String tmp = new String();
                for (int j = 0; j < unApprovedFriends.length; j++) {
                    tmp = tmp.concat(unApprovedFriends[j].userName).concat(",");            
                }
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.stat_sample)
                .setContentTitle(getText(R.string.new_friend_request_exist));
                /*Notification notification = new Notification(R.drawable.stat_sample, 
                        getText(R.string.new_friend_request_exist),
                        System.currentTimeMillis());*/

                Intent i = new Intent(this, UnApprovedFriendList.class);
                i.putExtra(FriendInfo.FRIEND_LIST, tmp);                

                PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                        i, 0);

                mBuilder.setContentText("You have new friend request(s)");


                mBuilder.setContentIntent(contentIntent);


                NM.notify(R.string.new_friend_request_exist, mBuilder.build());         
            }
            else
            {

                NM.cancel(R.string.new_friend_request_exist);           
            }
        }

    }


    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        super.onListItemClick(l, v, position, id);      

        Intent i = new Intent(this, Messaging.class);
        FriendInfo friend = friendAdapter.getItem(position);
        i.putExtra(FriendInfo.USERNAME, friend.userName);
        i.putExtra(FriendInfo.PORT, friend.port);
        i.putExtra(FriendInfo.IP, friend.ip);       
        startActivity(i);
    }




    @Override
    protected void onPause() 
    {
        unregisterReceiver(messageReceiver);        
        unbindService(mConnection);
        super.onPause();
    }

    @Override
    protected void onResume() 
    {

        super.onResume();
        bindService(new Intent(FriendList.this, IMService.class), mConnection , Context.BIND_AUTO_CREATE);

        IntentFilter i = new IntentFilter();

        i.addAction(IMService.FRIEND_LIST_UPDATED);


        registerReceiver(messageReceiver, i);           


    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {     
        boolean result = super.onCreateOptionsMenu(menu);       

        menu.add(0, ADD_NEW_FRIEND_ID, 0, R.string.add_new_friend);
        menu.add(0, CREATE_GROUP_ID, 0, R.string.create_group);
        menu.add(0, EXIT_APP_ID, 0, R.string.exit_application);     

        return result;
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) 
    {       

        switch(item.getItemId()) 
        {     
            case ADD_NEW_FRIEND_ID:
            {
                Intent i = new Intent(FriendList.this, AddFriend.class);
                startActivity(i);
                return true;
            }
            case CREATE_GROUP_ID:
            {
                Intent i = new Intent(FriendList.this, CreateGroup.class);
                startActivity(i);
                return true;
            }   
            case EXIT_APP_ID:
            {
                imService.exit();
                finish();
                return true;
            }           
        }

        return super.onMenuItemSelected(featureId, item);       
    }   

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);




    }

下一步 Activity 它的工作原理意味着首先会要求输入群组名称,然后它会显示所有朋友,我可以 select n 个朋友然后一个按钮命名为创建。

现在群组已成功创建,有 n 个朋友,这些都是我保存到数据库中的数据。 现在我的问题是创建群组后我想在之前的 activity.

中显示群组详细信息

谁能帮我解决这个问题

添加新组后返回上一个 activity 时必须刷新列表数据。从第一个 activity.

onResume 中的数据库中检索数据

除了你需要调用适配器视图的 NotifyDatasetChanged 方法之外,我同意以上答案,这将使用提供的新数据重绘列表内容