android自定义控件(邮箱边写边出格式邮箱)
android可以自定义控件,最近接触到两种自定义控件,记下,为以后遇到时可以复用
public class AutoCompleteEmailEdit extends AutoCompleteTextView {
private ArrayList<String> candidateString = null;
private ArrayAdapter<String> adapter = null;
private Context mContext = null;
private String previousUserName = 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 (previousUserName != null) {
String tempPrevStr = previousUserName.concat(mEmailSuffix[i].toString());
adapter.remove(tempPrevStr);
}
}
previousUserName = name;
}
}
摘自 chengxibeauty
补充:移动开发 , Android ,