The function of displaying a like user in a custom control of android and entering the User Home Page by user name

Source: Internet
Author: User

The function of displaying a like user in a custom control of android and entering the User Home Page by user name

:

The above effect is similar to the interface for displaying a like user. We can click different nicknames to enter the personal homepage of each person.

 

For public controls, click the git address below the article.

 

Step 1:

We create a class for each person who likes to represent personal information:

Person:

 

public class Person {public String name;public int age;}

It's easy, just a name and age

 

Step 2:

Custom TextView Control

Create a PersonListView and inherit the abstract class BaseOnTextView:

 

Public class PersonListView extends BaseOnTextView
 
  
{Public PersonListView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);} public PersonListView (Context context, AttributeSet attrs) {super (context, attrs);} public PersonListView (Context context) {super (context);} public void setVoteName (ArrayList
  
   
List, int index) {this. getInfo (list); setVoteList (list, index);}/*** set the like name */@ Overridepublic String getVoteName (Person data) {return data. name;}/*** get the likes */@ Overridepublic List
   
    
GetInfo (List
    
     
List) {return list ;}}
    
   
  
 

 

 

Step 3:

Put the custom TextView in xml.

Person_item.xml:

 


Step 4:

 

Create an Activity.

MainActivity:

 

Public class MainActivity extends Activity {private ListView lv_lsit; private ArrayList
 
  
PersonList = new ArrayList
  
   
(); Private PersonListAdapter mPersonListAdapter = new PersonListAdapter (); @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initView ();} private void initView () {String [] strs = {Naruto, Kakashi, Naruto, Yuzhi po, Yuzhi Pozos, Sakura, Li locks, da shewan, it is difficult to get a name. Please do not hurt me again}; for (int I = 0; I
   
    

 

Finally, add an event to The onClick method in the TextViewSpan class.

 

 

Public class TextViewSpan
     
      
Extends ClickableSpan {private String clickString; private Context mContext; private int selectClick; private T votePerson; public TextViewSpan (String clickString, Context context, int selectClick) {this. clickString = clickString; this. mContext = context; this. selectClick = selectClick;}/*** sets the liked person information ** @ param t */public void setInfo (T t) {votePerson = t ;} @ Overridepublic void updateDrawState (TextPaint ds) {ds. setColor (mContext. getResources (). getColor (R. color. main_link); ds. setUnderlineText (false) ;}@ Overridepublic void onClick (View widget) {switch (selectClick) {case 0: // open the personal main interface Person person = (Person) votePerson; Toast. makeText (mContext, person. name, Toast. LENGTH_SHORT ). show (); break; case 1: break; default: break ;}}}
     


 

 

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.