Android can customize controls. Two custom controls have been recently exposed and can be reused later.
Public class AutoCompleteEmailEdit extends AutoCompleteTextView {
Private ArrayList <String> candidateString = null;
Private ArrayAdapter <String> adapter = null;
Private Context mContext = null;
Private String previususername = null;
Public AutoCompleteEmailEdit (Context context ){
Super (context );
// TODO Auto-generated constructor stub
}
Public AutoCompleteEmailEdit (Context context, AttributeSet attrs ){
Super (context, attrs );
MContext = context;
}
Public void init (){
SetInputType (InputType. TYPE_TEXT_VARIATION_EMAIL_ADDRESS );
CandidateString = new ArrayList <String> ();
Adapter = new ArrayAdapter <String> (mContext, R. layout. list_candidate, candidateString );
SetAdapter (adapter );
SetThreshold (1 );
}
Public void createCandidateEmail (String name ){
CharSequence [] mEmailSuffix = null;
MEmailSuffix = getResources (). getTextArray (R. array. EmailSuffix );
If (name = null | name. indexOf ('@')! =-1 ){
Return;
}
For (int I = 0; I <mEmailSuffix. length; I ++ ){
String tempStr = name. concat (mEmailSuffix [I]. toString ());
Adapter. add (tempStr );
If (previususername! = Null ){
String tempPrevStr = previususername. concat (mEmailSuffix [I]. toString ());
Adapter. remove (tempPrevStr );
}
}
Previususername = name;
}
}
From chengxibeauty