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 ;}}}