Android ApiDemos example resolution (173): Views-& gt; Lists-& gt; 6. Lis

Source: Internet
Author: User

This View is composed of two textviews. One TextView displays the Title and the other displays the content. The difference is that it adds the setExpanded method to control the TextView visibility of the displayed content:


[Java]
Public void setExpanded (boolean expanded ){
MDialogue. setVisibility (expanded? VISIBLE: GONE );
}

Public void setExpanded (boolean expanded ){
MDialogue. setVisibility (expanded? VISIBLE: GONE );
}

Class SpeechListAdapter adds a method to change the visibility of the list items, similar to MVC changing the Model value. In this case, you need to call yydatasetchanged () to notify the View data source to change to update the UI.

 

[Java]
/**
* Make a SpeechView to hold each row.
* @ See android. widget. ListAdapter # getView (int,
Android. view. View, android. view. ViewGroup)
*/
Public View getView (int position, View convertView,
ViewGroup parent ){
SpeechView sv;
If (convertView = null ){
Sv = new SpeechView (mContext,
MTitles [position],
MDialogue [position],
MExpanded [position]);
} Else {
Sv = (SpeechView) convertView;
Sv. setTitle (mTitles [position]);
Sv. setDialogue (mDialogue [position]);
Sv. setExpanded (mExpanded [position]);
}
 
Return sv;
}
 
Public void toggle (int position ){
MExpanded [position] =! MExpanded [position];
NotifyDataSetChanged ();
}

/**
* Make a SpeechView to hold each row.
* @ See android. widget. ListAdapter # getView (int,
Android. view. View, android. view. ViewGroup)
*/
Public View getView (int position, View convertView,
ViewGroup parent ){
SpeechView sv;
If (convertView = null ){
Sv = new SpeechView (mContext,
MTitles [position],
MDialogue [position],
MExpanded [position]);
} Else {
Sv = (SpeechView) convertView;
Sv. setTitle (mTitles [position]);
Sv. setDialogue (mDialogue [position]);
Sv. setExpanded (mExpanded [position]);
}

Return sv;
}

Public void toggle (int position ){
MExpanded [position] =! MExpanded [position];
NotifyDataSetChanged ();
}

In this example, we can also see that ListActivity is very flexible. Different views can be used for list items. Theoretically, different list items can be displayed by selecting any View.

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.