Silicon Valley social 12-group list page, Silicon Valley social 12-list

Source: Internet
Author: User

Silicon Valley social 12-group list page, Silicon Valley social 12-list

1) Page Layout

<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" xmlns: app = "http://schemas.android.com/apk/res-auto" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <com. hyphenate. easeui. widget. easeTitleBar app: titleBarTitle = "group list" android: layout_width = "match_parent" android: layout_height = "wrap_content"> </com. hyphenate. easeui. widget. easeTitleBar> <ListView android: id = "@ + id/lv_grouplist" android: layout_width = "match_parent" android: layout_height = "match_parent"> </ListView> </LinearLayout>

2) Add a header layout for Listview

// Get the header layout viewView headerView = View. inflate (GroupListActivity. this, R. layout. header_group_list, null); // Add the header layout viewlv_group_list.addHeaderView (headerView );

3) Listview Initialization

// Create the adapter mGroupListAdapter = new GroupListAdapter (GroupListActivity. this); // Add the adapter to the listview lv_group_list.setAdapter (mGroupListAdapter );

4) Listview Adapter

Public class GroupListAdapter extends BaseAdapter {private Context mContext; private List <EMGroup> mEMGroups = new ArrayList <> (); public GroupListAdapter (Context context) {mContext = context ;} // refresh method public void refresh (List <EMGroup> eMGroups) {if (eMGroups! = Null & eMGroups. size ()> = 0) {// load data mEMGroups. clear (); mEMGroups. addAll (eMGroups); // notifyDataSetChanged () ;}@ Override public int getCount () {return mEMGroups = null? 0: mEMGroups. size () ;}@ Override public Object getItem (int position) {return mEMGroups. get (position) ;}@ Override public long getItemId (int position) {return position ;}@ Override public View getView (int position, View convertView, ViewGroup parent) {// create or obtain viewhoder ViewHolder holder = null; if (convertView = null) {holder = new ViewHolder (); convertView = View. inflate (mContext, R. layout. item_group_list, null); holder. TV _name = (TextView) convertView. findViewById (R. id. TV _group_list_name); convertView. setTag (holder);} else {holder = (ViewHolder) convertView. getTag () ;}// obtain the current item data EMGroup emGroup = mEMGroups. get (position); // display the data holder. TV _name.setText (emGroup. getGroupName (); // return convertview return convertView;} static class ViewHolder {TextView TV _name ;}}

5) Obtain group contact information from the email service

// Obtain group information through the Internet private void getGroupFromHxServier () Rule model.getinstace().getgolbalthreadpool(cmd.exe cute (new Runnable () {@ Overridepublic void run () {try {// obtain group information through the Internet em. getInstance (). groupManager (). getJoinedGroupsFromServer (); runOnUiThread (new Runnable () {@ Overridepublic void run () {Toast. makeText (GroupListActivity. this, "group information loaded successfully", Toast. LENGTH_SHORT ). show (); // refresh the mGroupListAdapter. refresh (EMClient. getInstance (). groupManager (). getAllGroups () ;}});} catch (HyphenateException e) {e. printStackTrace (); runOnUiThread (new Runnable () {@ Overridepublic void run () {Toast. makeText (GroupListActivity. this, "failed to load group information", Toast. LENGTH_SHORT ). show ();}});}}});}

6) refresh the page with Listview

// Refresh the display mGroupListAdapter. refresh (EMClient. getInstance (). groupManager (). getAllGroups ());

7) Click events of group list entries

// Click Event lv_group_list.setOnItemClickListener (new AdapterView. OnItemClickListener () {@ Overridepublic void onItemClick (AdapterView <?> Parent, View view, int position, long id) {// jump to the chat page Intent intent = new Intent (GroupListActivity. this, ChatActivity. class); // obtain the group idString groupId = EMClient. getInstance (). groupManager (). getAllGroups (). get (position-1 ). getGroupId (); intent. putExtra (EaseConstant. EXTRA_USER_ID, groupId); // Save the group chat type intent. putExtra (EaseConstant. EXTRA_CHAT_TYPE, EaseConstant. CHATTYPE_GROUP); startActivity (intent );}});

8) create a click listener for a new group

// The Click Event ll_group_list.setOnClickListener (new View. onClickListener () {@ Overridepublic void onClick (View v) {// jump to the new group page Intent intent = new Intent (GroupListActivity. this, NewGroupActivity. class); startActivity (intent );}});

9) refresh the page when the page is visible

@ Overrideprotected void onResume () {super. onResume (); // refresh the mGroupListAdapter. refresh (EMClient. getInstance (). groupManager (). getAllGroups ());}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.