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.