2, for focused TextView (more than one line of text can not be displayed) effect
For a single textview, you can add three properties directly to the TextView control parameter:
Android:singleline= "true" (an ellipsis is shown on one line)
Android:ellipsize= "Marquee" (one line shows no ellipses)
Android:focusable= "true"
Android:focusableintouchmode= "true" (the last two combinations make a single textview achievable)
The "marquee effect" implementation for two or more textview or complex structures requires a custom control, as follows:
Start by creating two different TextView controls, each with their respective IDs, and then create a new class that inherits from TextView.
Implement all of the constructor methods in the class method (by right-clicking to find constructor in generate, double-click All constructed classes)
After all construction methods are implemented, add the public boolean isFocused () {return true;} and return the XML file finally
, replace the TextView control with a custom <com.sub.coder.marqueetext ...> to achieve the dual marquee effect!
3, how to achieve the Autocompletetextview (according to the input character auto-complete, category Baidu search box) use
The first step, drag and drop the Autocompletetextview control, modify the hint= "Please enter what you want to search" and in the. java file for the control initialization operation
Second step, create a new adapter (Adapter) and initialize the data source array (to match the search content)
The third step is to bind the Autocompletetextview control to the adapter (Adapter) to
Also note that you can modify the number of strings when starting a match by android:completionthreshold= the "2" control property setting
Specific implementation code: package Com.sub.coder;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.ArrayAdapter;
Import Android.widget.AutoCompleteTextView;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
Private Autocompletetextview Actextview;
Private string[] res = {"Beijing1", "Beijing2", "Bejing3", "Shanghai1", "SHANGHAI2"};
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Actextview = (Autocompletetextview) Findviewbyid (R.id.autocompletetextview);
arrayadapter<string> adapter = new Arrayadapter<string> (this,android. R.layout.simple_list_item_1,res);
Actextview.setadapter (adapter);
}
}
4, how to achieve multiautocompletetextview (similar to the multi-match mailbox recipients), ibid, need to set up a number of separator code, specifically as follows:
Package com.sub.coder;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.ArrayAdapter;
Import Android.widget.AutoCompleteTextView;
Import Android.widget.MultiAutoCompleteTextView;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
Private Autocompletetextview Actextview;
Private Multiautocompletetextview Mactextview;
Private string[] res = {"Beijing1", "Beijing2", "Bejing3", "Shanghai1", "SHANGHAI2"};
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Actextview = (Autocompletetextview) Findviewbyid (R.id.autocompletetextview);
arrayadapter<string> adapter = new Arrayadapter<string> (this,android. R.layout.simple_list_item_1,res);
Actextview.setadapter (adapter);
Mactextview = (Multiautocompletetextview) Findviewbyid (R.id.multiautocompletetextview);
Mactextview.setadapter (adapter);
Mactextview.settokenizer (New Multiautocompletetextview.commatokenizer ());
}
5, using ToggleButton button and ImageView control to achieve the switch effect:
First, the ToggleButton button and the ImageView control are established in the XML file, and then they are initialized in. Java, implemented in this class. Oncheckedchangelistener interface,
A method is then used to listen for Tb.setoncheckedchangelistener (this) after initialization is completed, and finally, a three-mesh operator is used in the method constructed to implement the interface to perform the current
The state of the button and the corresponding state of the picture switch.
Package com.sub.coder;
Import android.app.Activity;
Import Android.os.Bundle;
Import android.widget.*;
public class MyActivity extends Activity implements compoundbutton.oncheckedchangelistener{
Private ToggleButton TB;
Private ImageView img;
Private string[] res = {"Beijing1", "Beijing2", "Bejing3", "Shanghai1", "SHANGHAI2"};
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
TB = (ToggleButton) Findviewbyid (R.id.togglebutton);
img = (ImageView) Findviewbyid (R.id.imageview);
Tb.setoncheckedchangelistener (this);
}
@Override
public void OnCheckedChanged (Compoundbutton buttonview, Boolean isChecked) {
Img.setbackgroundresource (isChecked? R.drawable.on:r.drawable.off);
}
}
Third day: Formal programming the third days, learning the contents of TextView, Autocompletetextview, Multiautocompletetextview and ToggleButton, Checkedbox, RadioButton and other related practices