本文整理汇总了Java中android.widget.EditText.setText方法的典型用法代码示例。如果您正苦于以下问题:Java EditText.setText方法的具体用法?Java EditText.setText怎么用?Java EditText.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.EditText
的用法示例。
在下文中一共展示了EditText.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: numberDecimal
import android.widget.EditText; //导入方法依赖的package包/类
/**
* 自动补齐 0 或者 小数点
*
* @param mContent EditText
* @param mDecimal 小数位数
*/
private void numberDecimal(EditText mContent, int start, int count, int mDecimal) {
String val = mContent.getText().toString();
if (StringUtils.isEmpty(val))
return;
int index;
if ((index = val.indexOf(".")) != -1) {
if (index == 0) {
val = "0" + val;
mContent.setText(val);
mContent.setSelection(val.length());
return;
}
if (val.substring(index + 1).length() > mDecimal) {
mContent.setText(val.substring(0, start));
mContent.setSelection(val.length() - count);
}
} else {
if ("0".equals(val)) {
val += ".";
mContent.setText(val);
mContent.setSelection(val.length());
}
}
}
示例2: EditProductFeatureDialog
import android.widget.EditText; //导入方法依赖的package包/类
/**
* @param product Product that the feature belongs to
* @param feature Feature that's being edited
* @param context Activity context
* @param onFeatureChanged Callback that's called when the feature is changed
*/
public EditProductFeatureDialog(final Product product,
final ProductFeature feature,
Context context,
final CustomCallback onFeatureChanged) {
super(context,
R.layout.dialog_edit_product_feature,
"Edit feature");
final EditText editTextLevel = (EditText) findViewById(R.id.editTextFeatureLevel);
String stringCurrentLevel = "" + product.getLevelOfAFeature(feature);
editTextLevel.setText(stringCurrentLevel);
TextView textView = (TextView) findViewById(R.id.textViewFeatureName);
textView.setText(feature.getName());
setOkAction(new View.OnClickListener() {
@Override
public void onClick(View v) {
product.addFeature(feature, Integer.parseInt(editTextLevel.getText().toString()));
onFeatureChanged.callBack();
dismiss();
}
});
}
示例3: onCreate
import android.widget.EditText; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc_attenuation);
Intent intent = getIntent();
fEnergyList = intent.getDoubleArrayExtra(DisplayMaterialActivity.ATTEN_ENERGY);
fCoeffList = intent.getDoubleArrayExtra(DisplayMaterialActivity.ATTEN_COEFF);
fDensity = intent.getDoubleExtra(SearchOptionSelect.SEARCH_OBJECT_DENSITY, 0.0);
EditText editTextDensity = (EditText) findViewById(R.id.editTextDensity);
editTextDensity.setText(Double.toString(fDensity));
}
示例4: handleEmoticonText
import android.widget.EditText; //导入方法依赖的package包/类
/**
* 处理带表情的文本(显示表情符号)
*
* @param editText
* @param content
* @param context
*/
public static void handleEmoticonText(EditText editText, String content, Context context) {
SpannableStringBuilder sb = new SpannableStringBuilder(content);
String regex = "\\[(\\S+?)\\]";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
Iterator<Emoticon> iterator;
Emoticon emoticon = null;
while (m.find()) {
iterator = emoticonList.iterator();
String tempText = m.group();
while (iterator.hasNext()) {
emoticon = iterator.next();
if (tempText.equals(emoticon.getContent())) {
//转换为Span并设置Span的大小
sb.setSpan(new VerticalImageSpan(context,
decodeSampledBitmapFromResource(context.getResources(),
emoticon.getImageUri(), dip2px(context, 16), dip2px(context, 16))),
m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
}
}
}
editText.setText(sb);
editText.setSelection(sb.length());
}
示例5: setEtText
import android.widget.EditText; //导入方法依赖的package包/类
/**
* 设置 {@link EditText} 文本,并且移动光标到末尾.
*
* @param et {@link EditText}
* @param text 文本
*/
public static void setEtText(EditText et, CharSequence text)
{
et.setText(text);
//这里进行修改,通过text.length() 设置的 Selection 有错误
et.setSelection(et.getText().length());
}
示例6: onCreateDialogView
import android.widget.EditText; //导入方法依赖的package包/类
@Override
protected View onCreateDialogView() {
View root = super.onCreateDialogView();
mText = (EditText)root.findViewById(R.id.numberpicker_edit);
mText.setText(""+this.getPersistedInt(0));
return root;
}
示例7: addSecurityQuestion
import android.widget.EditText; //导入方法依赖的package包/类
private void addSecurityQuestion(SecurityQuestionModel securityQuestion) {
_logger.Debug("addSecurityQuestion");
final EditText questionEditText = new EditText(_context);
final EditText answerEditText = new EditText(_context);
final ArrayList<EditText> editPair = new ArrayList<>();
editPair.add(questionEditText);
editPair.add(answerEditText);
final Button removeSecurityQuestions = new Button(_context);
removeSecurityQuestions.setBackgroundColor(COLOR_BLACK_MAX_ALPHA);
removeSecurityQuestions.setText("X");
removeSecurityQuestions.setGravity(Gravity.END);
removeSecurityQuestions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
_securityQuestionEditTextList.remove(editPair);
_securityButtonList.remove(removeSecurityQuestions);
_linearLayoutSecurityQuestions.removeView(questionEditText);
_linearLayoutSecurityQuestions.removeView(answerEditText);
_linearLayoutSecurityQuestions.removeView(removeSecurityQuestions);
}
});
_linearLayoutSecurityQuestions.addView(removeSecurityQuestions);
_linearLayoutSecurityQuestions.addView(questionEditText);
_linearLayoutSecurityQuestions.addView(answerEditText);
_securityQuestionEditTextList.add(editPair);
_securityButtonList.add(removeSecurityQuestions);
if (securityQuestion != null) {
questionEditText.setText(securityQuestion.GetQuestion());
answerEditText.setText(securityQuestion.GetAnswer());
}
}
示例8: showInputedError
import android.widget.EditText; //导入方法依赖的package包/类
/**字符不合法提示(et == null ? toast : hint)
* @param context
* @param et
* @param string
* @return
*/
public static boolean showInputedError(Activity context, EditText et, String string) {
if (context == null || StringUtil.isNotEmpty(string, false) == false) {
Log.e(TAG, "showInputedError context == null || et == null || StringUtil.isNotEmpty(string, false) == false >> return false;");
return false;
}
if (et == null) {
Toast.makeText(context, StringUtil.getTrimedString(string), Toast.LENGTH_SHORT).show();
} else {
et.setText("");
et.setHint(string);
et.setHintTextColor(context.getResources().getColor(R.color.red));
}
return false;
}
示例9: onCreate
import android.widget.EditText; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = getIntent();
if (intent == null || !Intents.SearchBookContents.ACTION.equals(intent.getAction())) {
finish();
return;
}
isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
if (LocaleManager.isBookSearchUrl(isbn)) {
setTitle(getString(R.string.sbc_name));
} else {
setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn);
}
setContentView(R.layout.search_book_contents);
queryTextView = (EditText) findViewById(R.id.query_text_view);
String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
if (initialQuery != null && !initialQuery.isEmpty()) {
// Populate the search box but don't trigger the search
queryTextView.setText(initialQuery);
}
queryTextView.setOnKeyListener(keyListener);
queryButton = findViewById(R.id.query_button);
queryButton.setOnClickListener(buttonListener);
resultListView = (ListView) findViewById(R.id.result_list_view);
LayoutInflater factory = LayoutInflater.from(this);
headerView = (TextView) factory.inflate(R.layout.search_book_contents_header,
resultListView, false);
resultListView.addHeaderView(headerView);
}
示例10: onCreate
import android.widget.EditText; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginTimes = -1;
Bundle bundle = getIntent().getExtras();
strEmail = bundle.getString(AppConstants.Email);
// 使用全局变量的方式传值
CinemaBean cinema = GlobalVariables.Cinema;
if (cinema != null) {
cinemaName = cinema.getCinemaName();
} else {
cinemaName = "";
}
etEmail = (EditText) findViewById(R.id.email);
etEmail.setText(strEmail);
etPassword = (EditText) findViewById(R.id.password);
// 登录事件
Button btnLogin = (Button) findViewById(R.id.sign_in_button);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoLoginActivity();
}
});
// 获取2个MobileAPI,获取天气数据,获取城市数据
loadWeatherData();
loadCityData();
}
示例11: onCreate
import android.widget.EditText; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_convert_code);
// initialize renderer
converter = MongolCode.INSTANCE;
etCodeWindow = (EditText) findViewById(R.id.etCodeWindow);
etCodeWindow.setText("ᠮᠤᠩᠭᠤᠯ"); // Mongol
}
示例12: showEditTextWarning
import android.widget.EditText; //导入方法依赖的package包/类
/**
* 检测EditText内容是否为空,若为空则进行警告提醒
*
* @param et
* @param msg
* @return
*/
public static boolean showEditTextWarning(EditText et, String msg) {
if (TextUtils.isEmpty(et.getText())) {
et.setError(msg);
et.requestFocus();
et.setText("");
return true;
}
return false;
}
示例13: setNumber
import android.widget.EditText; //导入方法依赖的package包/类
private void setNumber(View row, String number) {
final EditText numberEdit = (EditText) row.findViewById(R.id.edit_number);
numberEdit.setText(number);
if (number == null || number.isEmpty()) {
numberEdit.postDelayed(new Runnable() {
@Override
public void run() {
numberEdit.requestFocus();
}
}, 100);
}
}
示例14: onCreate
import android.widget.EditText; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
balanceTxt = (EditText)findViewById(R.id.balanceTxt);
riskTxt = (EditText)findViewById(R.id.riskTxt);
startDateButton = (Button)findViewById(R.id.setStartDate);
endDateButton = (Button)findViewById(R.id.setEndDate);
balanceTxt.setText(String.valueOf(app.getInput().balance));
riskTxt.setText((String.valueOf(app.getInput().risk)));
startDateButton.setText(App.current.getInput().startDate.getTime().toString());
endDateButton.setText(App.current.getInput().endDate.getTime().toString());
}
示例15: createEditTextAtIndex
import android.widget.EditText; //导入方法依赖的package包/类
private void createEditTextAtIndex(String text, int index) {
EditText e = createEditText("", dip2px(10));
e.setText(text);
allLayout.addView(e, index);
}