Android uidesign: QQ-like friend list group hover, custom Header, pull-down refresh combined with Demo, androidheader

Source: Internet
Author: User

Android uidesign: QQ-like friend list group hover, custom Header, pull-down refresh combined with Demo, androidheader

I learned Pulltorefresh and pinnedheaderexpanablelistview before, but it is a little troublesome to combine them. Especially QQ. It is not simply the first group. There are several buttons on the group, as well as the search box. You can also slide and hover over the group. I tried several methods and found bugs. The last method used.
1. android. v4 used by pulltorefresh comes with it.
2. hover and group online, then I changed the style of the first group to a custom menu, and cleared the child. this looks like sliding together a custom layout and listview.
3. The following is a style chart

The whole part is slide.

After the pull-down refresh, there will be a color belt at the top. A little fine. This is the result of the system.

This is the hover effect, and the previous custom menu is sliding up.
The following is the core code, which is very concise.

Package com. android. activity; import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. support. v4.widget. swipeRefreshLayout; import android. support. v4.widget. swipeRefreshLayout. onRefreshListener; import android. view. view; import android. widget. adapterView; import android. widget. expandableListAdapter; import android. widget. expandableListView; import android. widget. expandableListView. onChildClickListener; import android. widget. expandableListView. onGroupClickListener; import android. widget. toast; import com. android. r; import com. android. pinnedheader. extends; public class MainActivity extends Activity {private PinnedHeaderExpandableListView explistview; private SwipeRefreshLayout swipeRefreshLayout; private String [] [] childrenData = new String [10] [10]; private String [] groupData = new String [5]; private int expandFlag =-1; // expand the private MainAdapter adapter in the Control List; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. layout_main); initView (); initData ();}/*** initialize VIEW */private void initView () {explistview = (PinnedHeaderExpandableListView) findViewById (R. id. explistview); swipeRefreshLayout = (SwipeRefreshLayout) findViewById (R. id. swipe_container); // set the animation color when refreshing. You can set four swipeRefreshLayout. setColorSchemeResources (android. r. color. holo_blue_light, android. r. color. holo_red_light, android. r. color. holo_orange_light, android. r. color. holo_green_light); swipeRefreshLayout. setOnRefreshListener (new OnRefreshListener () {@ Override public void onRefresh () {new Handler (). postDelayed (new Runnable () {@ Override public void run () {swipeRefreshLayout. setRefreshing (false) ;}}, 6000) ;}});}/*** initialize data */private void initData () {for (int I = 0; I <5; I ++) {groupData [I] = "group" + I ;}for (int I = 1; I <5; I ++) {for (int j = 0; j <10; j ++) {childrenData [I] [j] = "qq" + j ;}} // set the floating head VIEW to explistview. setHeaderView (View. inflate (MainActivity. this, R. layout. group, null); adapter = new MainAdapter (childrenData, groupData, getApplicationContext (), explistview); explistview. setAdapter (adapter); explistview. setOnChildClickListener (new OnChildClickListener () {@ Override public boolean onChildClick (ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {Toast. makeText (MainActivity. this, "group:" + groupData [groupPosition] + ", friend:" + childrenData [groupPosition] [childPosition], Toast. LENGTH_SHORT ). show (); return false ;}});}}

All you need to do is set the listener and transmit data. Remember that the first group of data is not displayed, and the child value must be 0.
The menu style and group style are set in getview.

Package com. android. activity; import com. android. r; import com. android. pinnedheader. pinnedHeaderExpandableListView; import android. content. context; import android. opengl. visibility; import android. util. sparseIntArray; import android. view. layoutInflater; import android. view. view; import android. view. viewGroup; import android. widget. baseExpandableListAdapter; import android. widget. imageView; import android. widg Et. textView; import android. widget. absListView. layoutParams; import android. widget. toast; public class MainAdapter extends BaseExpandableListAdapter {private String [] [] childrenData; public String [] groupData; private Context context; private PinnedHeaderExpandableListView listView; private LayoutInflater inflater; public MainAdapter (String [] [] childrenData, String [] groupData, Context context, Pinned HeaderExpandableListView listView) {this. groupData = groupData; this. childrenData = childrenData; this. context = context; this. listView = listView; inflater = LayoutInflater. from (this. context) ;}@ Override public Object getChild (int groupPosition, int childPosition) {return childrenData [groupPosition] [childPosition] ;}@ Override public long getChildId (int groupPosition, int childPosition) {retur N 0 ;}@ Override public View getChildView (int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {View view = null; if (convertView! = Null) {view = convertView;} else {view = inflater. inflate (R. layout. child, null);} TextView text = (TextView) view. findViewById (R. id. childto); text. setText (childrenData [groupPosition] [childPosition]); return view ;}@ Override public int getChildrenCount (int groupPosition) {if (groupPosition <0) return 0; return childrenData [groupPosition]. length ;}@ Override public Object getGroup (int groupPosit Ion) {return groupData [groupPosition];} @ Override public int getGroupCount () {return groupData. length ;}@ Override public long getGroupId (int groupPosition) {return 0 ;}@ Override public View getGroupView (int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {View view = null; // menu if (groupPosition = 0) {view = inflater. inflate (R. layout. menu, null); view. setLayoutParams (New LayoutParams (ViewGroup. layoutParams. MATCH_PARENT, 80); view. setTag (1); TextView btn1 = (TextView) view. findViewById (R. id. btn1); btn1.setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {Toast. makeText (context, "special concern", Toast. LENGTH_SHORT ). show () ;}}); return view ;}// normal group if (convertView! = Null & (Integer) convertView. getTag () = 0) {view = convertView;} else {view = inflater. inflate (R. layout. group, null); view. setTag (0);} TextView text = (TextView) view. findViewById (R. id. groupto); if (isExpanded) {text. setText ("-" + groupData [groupPosition]);} else {text. setText ("+" + groupData [groupPosition]);} return view ;}@ Override public boolean hasStableIds () {return true ;}@ Override public boolean isChildSelectable (int groupPosition, int childPosition) {return true ;}}

Isn't it very rare? The code that needs to be changed is the two files.
Project is here: My github address
Stamp: https://github.com/younfor/PinnedAndPulledHeaderListView

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.