Similar to the pop-up box comment function of WeChat 5.x circle of friends, the 5. x comment function

Source: Internet
Author: User

Similar to the comment function in the pop-up box of the 5. x circle of friends, the comment function of the 5. x circle
To comment on a topic and display the comment list, you first need to use the ListView control,
The xml layout file in layout is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent" android: background = "@ drawable/list_selector" android: orientation = "horizontal" android: padding = "5dip"> <LinearLayout android: id = "@ + id/thumbnail" android: layout_width = "120dip" android: layout_height = "120dip" android: layout_alignParentLeft = "true" android: l Ayout_marginRight = "5dip" android: background = "@ drawable/image_bg" android: padding = "1dip"> <ImageView android: id = "@ + id/group_image" android: layout_width = "match_parent" android: layout_height = "match_parent" android: scaleType = "centerInside" android: src = "@ drawable/copyright"/> </LinearLayout> <TextView android: id = "@ + id/group_name" android: layout_width = "wrap_content" android: layout_height = "wrap_content "Android: layout_alignTop =" @ + id/thumbnail "android: layout_toRightOf =" @ + id/thumbnail "android: text =" test the friend circle comment function "android: textColor = "#040404" android: textSize = "15sp" android: textStyle = "bold" android: typeface = "sans"/> <TextView android: id = "@ + id/group_content" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_below = "@ + id/thumbnail" android: text = "when a dog sees a python, it just takes a picture of it." android Oid: textAppearance = "? Android: attr/textAppearanceLarge "android: textColor =" #343434 "android: textSize =" 12sp "/> <ImageView android: id =" @ + id/group_discuss_popup "android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignRight = "@ + id/group_content" android: layout_below = "@ + id/group_content" android: background = "@ drawable/coment_pressed"/> <TextView android: id = "@ + id/group_createtime" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignBottom = "@ + id/TextView09" android: layout_toLeftOf = "@ + id/group_discuss_popup" android: gravity = "right" android: text = "" android: textColor = "#10bcc9" android: textSize = "12sp" android: textStyle = "bold"/> <RelativeLayout android: id = "@ + id/rl_bottom" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_alignParentBottom = "true"> <Button android: id = "@ + id/group_discuss_submit" android: layout_width = "60dp" android: layout_height = "40dp" android: layout_alignParentRight = "true" android: layout_centerVertical = "true" android: layout_marginRight = "10dp" android: background = "@ drawable/chat_send_button_bg" android: onClick = "discussSubmit" android: text = "send" android: textSize = "20sp"/> <EditText android: id = "@ + id/group_discuss" android: layout_width = "fill_parent" android: layout_height = "40dp" android: layout_centerVertical = "true" android: layout_marginLeft = "10dp" android: layout_marginRight = "10dp" android: layout_toLeftOf = "@ id/group_discuss_submit" android: hint = "comment" android: singleLine = "true" android: textSize = "18sp"> <requestFocus/> </EditText> </RelativeLayout> <ListView android: id = "@ + id/group_discuss_list" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: Layout = "true" android: layout_below = "@ + id/group_discuss_popup" android: layout_marginTop = "14dp" android: divider = "# b5b5b5" android: dividerHeight = "1dp" android: listSelector = "@ drawable/list_selector"/> <TextView android: id = "@ + id/TextView09" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignBottom = "@ + id/thumbnail" android: layout_marginBottom = "40dp" android: layout_toRightOf = "@ + id/thumbnail" android: text = "time:" android: textColor = "#040404" android: textSize = "12sp" android: textStyle = "bold" android: typeface = "sans"/> </RelativeLayout>

Then, in the onCreate method of the Activity class, obtain the ListView instance and add a listener for each item.
// To prevent EditText on the layout interface from entering the page, the input method pops up to hide the soft keyboard getWindow (). setSoftInputMode (WindowManager. layoutParams. SOFT_INPUT_STATE_ALWAYS_HIDDEN); listView = (ListView) findViewById (R. id. group_discuss_list); this. discussOnItemClickListener ();

Method for adding a listener to each item: discussOnItemClickListener ()
/*** Event listener after the comment list is clicked */private void discussOnItemClickListener () {// Add the Click Event listView for each row of the comment. setOnItemClickListener (new OnItemClickListener () {@ Override public void onItemClick (AdapterView <?> Parent, View view, int position, long id) {// obtain the poster Map of the parent post <String, String> posMap = discussList. get (position); // set pusername pname = posMap. get ("username"); // get the instance editText disInputText = (EditText) findViewById (R. id. group_discuss); disInputText. setHint ("reply" + pname); disInputText. requestFocus ();}});}

Next, we will focus on the pop-up box after clicking the comment icon. In the onCreate method of the Activity class, we will add an onclick listener to the comment icon, and then add two pop-up comments and comments, add a listener for the two items. The Code is as follows:
GroupPopup = (ImageView) findViewById (R. id. group_discuss_popup); groupPopup. setOnClickListener (titlePopupOnclick); titlePopup = new TitlePopup (this, Utils. dip2px (this, 165), Utils. dip2px (this, 40); titlePopup. addAction (new ActionItem (this, "like", R. drawable. circle_praise); titlePopup. addAction (new ActionItem (this, "comment", R. drawable. circle_comment); titlePopup. setItemOnClickListener (this );

Listener method implementation
/*** Click the comment button to display the item click listener */@ Override public void onItemClick (ActionItem actionItem, int position) {// position, 0-like; 1-Comment switch (position) {case 0: // Like break; case 1: // comment EditText disInputText = (EditText) findViewById (R. id. group_discuss); disInputText. requestFocus (); break; default: break ;}}

When you click a comment in an item, the system requests the focus of the EditText input box and calls out the input method.

Finally, let's talk about adding the comment function. The demo just adds some comments. in the real environment, it is clear that you need to submit data to the server and then request a comment list from the server. in the demo, maintaining a global List in the Activity class is a simple alternative. then, a BaseAdapter implementation class is used to display the getView method.
Map <String, String> map = new HashMap <String, String> (); // set the map value to be displayed for map. put ("distime", DateUtils. formaterDate2YMDHm (new Date (System. currentTimeMillis (); map. put ("content", content); // sets the sender information map of the parent post. put ("puid", puid + ""); map. put ("pname", pname); // set your own information map. put ("uid", uid + ""); map. put ("username", username); discussList. add (map); ListLazyAdapter adapter = new ListLazyAdapter (this, discussList); listView. setAdapter (adapter); // set the adapter

Basically, the above three main functions can be used to implement a simple comment function after the pop-up box is clicked.

As follows:


Sample source code:
Http://download.csdn.net/detail/gaolu/7963061


The circle of friends cannot go out of the link. The pop-up dialog box keeps popping up. If you want to say "I love you" or something like that, a new dialog box pops up without filling in it.

You can search for an expert. There should be no virus.

Do I know when I send a message to someone else? Or are you new in the pop-up dialog box for other mobile phones?

It can be run in the background. As long as you do not quit, you can receive new messages. If you quit, you will not be able to display new messages. Thank you.

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.