android.widget.EditText#setText ( )源码实例Demo

下面列出了android.widget.EditText#setText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Hillffair17   文件: EditorView.java
private void onBackPress(EditText editText) {
    int selection = editText.getSelectionStart();
    if (selection == 0) {
        int viewIndex = allLayout.indexOfChild(editText);
        View v = allLayout.getChildAt(viewIndex - 1);

        if (v != null) {
            if (v instanceof EditText) {
                if ((int) v.getTag() != 1) {
                    String s1 = editText.getText().toString();
                    EditText q = (EditText) v;
                    String s2 = q.getText().toString();
                    allLayout.removeView(editText);
                    q.setText(s1 + s2);
                    q.requestFocus();
                    q.setSelection(s2.length(), s2.length());
                    lastEditText = q;
                }
            } else if (v instanceof ImageView) {
                allLayout.removeView(v);
            }

        }
    }

}
 
源代码2 项目: jterm-cswithandroid   文件: AnagramsActivity.java
private void processWord(EditText editText) {
    TextView resultView = (TextView) findViewById(R.id.resultView);
    String word = editText.getText().toString().trim().toLowerCase();
    if (word.length() == 0) {
        return;
    }
    String color = "#cc0029";
    if (dictionary.isGoodWord(word, currentWord) && anagrams.contains(word)) {
        anagrams.remove(word);
        color = "#00aa29";
    } else {
        word = "X " + word;
    }
    resultView.append(Html.fromHtml(String.format("<font color=%s>%s</font><BR>", color, word)));
    editText.setText("");
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.show();
}
 
源代码3 项目: sqlitemagic   文件: EditListNameFragment.java
@Override
protected void observeValidCreate(@NonNull EditText inputView, @NonNull Observable<String> createStream) {
  final long listId = getArguments().getLong(EXTRA_LIST_ID);
  final String currentListName = Select.column(ITEM_LIST.NAME)
      .from(ITEM_LIST)
      .where(ITEM_LIST.ID.is(listId))
      .takeFirst()
      .execute();
  inputView.setText(currentListName);
  inputView.setSelection(currentListName.length());
  createStream.observeOn(Schedulers.io())
      .flatMap(name -> Update
          .table(ITEM_LIST)
          .set(ITEM_LIST.NAME, name)
          .where(ITEM_LIST.ID.is(listId))
          .observe()
          .toObservable())
      .firstOrError()
      .subscribe();
}
 
源代码4 项目: fingen   文件: AccountsSetManager.java
public void editName(final AccountsSet accountsSet, Activity activity, final IOnEditAction onEditAction) {
    String title = activity.getString(R.string.ent_name);

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(title);
    final EditText input = (EditText) activity.getLayoutInflater().inflate(R.layout.template_edittext, null);
    input.setText(accountsSet.getAccountsSetRef().getName());
    builder.setView(input);

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            accountsSet.getAccountsSetRef().setName(input.getText().toString());
            onEditAction.onEdit(accountsSet);
        }
    });

    builder.show();
    input.requestFocus();
}
 
public void enDisUsername (boolean enable,String username) {
    TextView t = (TextView)v.findViewById(R.id.cloud_username_label);
    EditText e = (EditText)v.findViewById(R.id.cloud_username);
    e.setEnabled(enable);
    e.setText(username);
    if (enable) {
        t.setAlpha(1.0f);
        e.setAlpha(1.0f);
    }
    else {
        t.setAlpha(0.4f);
        e.setAlpha(0.4f);
    }

}
 
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mTargetFile = getArguments().getParcelable(ARG_TARGET_FILE);

    // Inflate the layout for the dialog
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(R.layout.edit_box_dialog, null);
    
    // Setup layout 
    String currentName = mTargetFile.getFileName();
    EditText inputText = ((EditText)v.findViewById(R.id.user_input));
    inputText.setText(currentName);
    int selectionStart = 0;
    int extensionStart = mTargetFile.isFolder() ? -1 : currentName.lastIndexOf(".");
    int selectionEnd = (extensionStart >= 0) ? extensionStart : currentName.length();
    if (selectionStart >= 0 && selectionEnd >= 0) {
        inputText.setSelection(
                Math.min(selectionStart, selectionEnd), 
                Math.max(selectionStart, selectionEnd));
    }
    inputText.requestFocus();
    
    // Build the dialog  
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.synox_AlertDialog);
    builder.setView(v)
           .setPositiveButton(R.string.common_ok, this)
           .setNegativeButton(R.string.common_cancel, this)
           .setTitle(R.string.rename_dialog_title);
    Dialog d = builder.create();
    d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return d;
}
 
源代码7 项目: freeiot-android   文件: ApSsidConfigFragment.java
public void initView(View rootView) {
       etSsid = (EditText) rootView.findViewById(R.id.et_ssid);
	etPwd = (EditText) rootView.findViewById(R.id.et_pwd);
	btnConfig = (Button) rootView.findViewById(R.id.btn_config);
	btnConfig.setOnClickListener(this);
	rootView.findViewById(R.id.back).setOnClickListener(this);
	rootView.findViewById(R.id.btn_exit).setOnClickListener(this);

	ssid = wifiConnectUtil.getCurrentWifiSSID(getClass().getSimpleName());
	etSsid.setText(ssid);
}
 
源代码8 项目: Social   文件: SecondNameActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second_name_activity_layout);

    handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case OkhttpUtil.MESSAGE_MODIFY_SECOND_NAME:
                    handleModifySecondName(msg);
                    break;
            }
        }
    };

    friend_id = getIntent().getStringExtra("friend_id");
    old_second_name = getIntent().getStringExtra("old_second_name");

    ActionBar actionBar = getSupportActionBar();
    actionBar.setLogo(R.mipmap.ic_arrow_back_white_24dp);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("备注");

    et_second_name = (EditText)this.findViewById(R.id.id_second_name_activity_et_second_name);
    et_second_name.setText(old_second_name);
}
 
源代码9 项目: SortableTableView   文件: CarTableDataAdapter.java
private View renderEditableCatName(final Car car) {
    final EditText editText = new EditText(getContext());
    editText.setText(car.getName());
    editText.setPadding(20, 10, 20, 10);
    editText.setTextSize(TEXT_SIZE);
    editText.setSingleLine();
    editText.addTextChangedListener(new CarNameUpdater(car));
    return editText;
}
 
源代码10 项目: MyOwnNotes   文件: SettingsActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	getActionBar().setDisplayHomeAsUpEnabled(true);

	setContentView(R.layout.activity_settings);
	
	//make sure that keyboard is not shown right up
	getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
	
	username = (EditText) findViewById(R.id.edittext_username);
	password = (EditText) findViewById(R.id.edittext_password);
	address = (EditText) findViewById(R.id.edittext_server_address);
	autoSync = (CheckBox) findViewById(R.id.checkbox_sync_automatically);
	defaultTitle = (CheckBox) findViewById(R.id.checkbox_defaultnotetitle);
	extensiveLogCat = (CheckBox) findViewById(R.id.checkbox_extensive_log);
	
	settings = PreferenceManager.getDefaultSharedPreferences(this);
	
	username.setText( settings.getString(PREF_USERNAME, ""));
	password.setText(settings.getString(PREF_PASSWOORD, ""));
	address.setText(settings.getString(PREF_ADDRESS, ""));
	autoSync.setChecked(settings.getBoolean(PREF_AUTOSYNC, true));
	defaultTitle.setChecked( settings.getBoolean(PREF_DEFAULT_TITLE, true));
	extensiveLogCat.setChecked(settings.getBoolean(PREF_EXTENSIVE_LOG, false));
}
 
源代码11 项目: YCCustomText   文件: HyperTextEditor.java
/**
 * 在特定位置插入EditText
 * @param index							位置
 * @param editStr						EditText显示的文字
 */
public synchronized void addEditTextAtIndex(final int index, CharSequence editStr) {
	try {
		EditText editText = createEditText("插入文字", EDIT_PADDING);
		if (!TextUtils.isEmpty(keywords)) {
			//搜索关键词高亮
			SpannableStringBuilder textStr = HyperLibUtils.highlight(
					editStr.toString(), keywords  , Color.parseColor("#EE5C42"));
			editText.setText(textStr);
		} else if (!TextUtils.isEmpty(editStr)) {
			//判断插入的字符串是否为空,如果没有内容则显示hint提示信息
			editText.setText(editStr);
		}

		// 请注意此处,EditText添加、或删除不触动Transition动画
		layout.setLayoutTransition(null);
		layout.addView(editText, index);
		// remove之后恢复transition动画
		layout.setLayoutTransition(mTransition);
		//插入新的EditText之后,修改lastFocusEdit的指向
		lastFocusEdit = editText;
		//获取焦点
		lastFocusEdit.requestFocus();
		//将光标移至文字指定索引处
		lastFocusEdit.setSelection(editStr.length(), editStr.length());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
源代码12 项目: listmyaps   文件: AnnotationsActivity.java
@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
	AppAdapter aa = (AppAdapter) getListAdapter();
	spi = aa.getItem(pos);
	View layout = getLayoutInflater().inflate(R.layout.annotionsdialog, null);
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	comment = (EditText) layout.findViewById(R.id.comment_input);
	comment.setText(MainActivity.noNull(spi.comment));
	tags = (EditText) layout.findViewById(R.id.tag_input);
	tags.setText(MainActivity.noNull(spi.tags));
	Drawable icon = spi.appInfo.loadIcon(getPackageManager());
	builder.setTitle(spi.displayName).setView(layout).setIcon(icon)
			.setPositiveButton(R.string.btn_save, this)
			.setNegativeButton(R.string.btn_cancel, this).show();
}
 
源代码13 项目: OpenYOLO-Android   文件: MainActivity.java
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

    EditText userNameField = (EditText)findViewById(R.id.user_name_field);
    if (getUsername().isEmpty()) {
        userNameField.setText(UserDataStore.getUserName(this));
    }

    ((EditText)findViewById(R.id.user_name_field))
            .addTextChangedListener(new UpdateUsernameWatcher());

    ((PinEntryView)findViewById(R.id.pin_entry_field))
            .addTextChangedListener(new RegenerateWatcher());

    ((EditText)findViewById(R.id.app_name_field))
            .addTextChangedListener(new RegenerateWatcher());

    findViewById(R.id.copy_password).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            copyPassword();
        }
    });

    generatePassword();
}
 
源代码14 项目: BotLibre   文件: IssueEditorActivity.java
public void appendFile(MediaConfig media) {
	String file = "\nattachment:\nhttp://"
			+ MainActivity.connection.getCredentials().host + MainActivity.connection.getCredentials().app + "/" + media.file + "\n";
	EditText text = (EditText) findViewById(R.id.detailsText);
	text.setText(text.getText().toString() + file);
}
 
源代码15 项目: MyHearts   文件: EditPagePort.java
private void initBody(RelativeLayout rlBody, float ratio) {
	svContent = new ScrollView(activity);
	rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	LinearLayout llContent = new LinearLayout(activity);
	llContent.setOrientation(LinearLayout.VERTICAL);
	svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	etContent = new EditText(activity);
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	etContent.setPadding(padding, padding, padding, padding);
	etContent.setBackgroundDrawable(null);
	etContent.setTextColor(0xff3b3b3b);
	etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	etContent.setText(sp.getText());
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	llContent.addView(etContent, lp);
	etContent.addTextChangedListener(this);

	rlThumb = new RelativeLayout(activity);
	rlThumb.setBackgroundColor(0xff313131);
	int	thumbWidth = (int) (DESIGN_THUMB_HEIGHT * ratio);
	int	xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT * ratio);
	lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth);
	lp.leftMargin = lp.rightMargin = lp.bottomMargin = lp.topMargin = padding;
	llContent.addView(rlThumb, lp);

	aivThumb = new AsyncImageView(activity) {
		public void onImageGot(String url, Bitmap bm) {
			thumb = bm;
			super.onImageGot(url, bm);
		}
	};
	aivThumb.setScaleToCropCenter(true);
	RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth);
	rlThumb.addView(aivThumb, rllp);
	aivThumb.setOnClickListener(this);
	initThumb(aivThumb);

	xvRemove = new XView(activity);
	xvRemove.setRatio(ratio);
	rllp = new RelativeLayout.LayoutParams(xWidth, xWidth);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	rlThumb.addView(xvRemove, rllp);
	xvRemove.setOnClickListener(this);
}
 
源代码16 项目: BotLibre   文件: IssueEditorActivity.java
public void appendFile(MediaConfig media) {
	String file = "\nattachment:\nhttp://"
			+ MainActivity.connection.getCredentials().host + MainActivity.connection.getCredentials().app + "/" + media.file + "\n";
	EditText text = (EditText) findViewById(R.id.detailsText);
	text.setText(text.getText().toString() + file);
}
 
源代码17 项目: RedReader   文件: PMSendActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {

	PrefsUtility.applyTheme(this);

	super.onCreate(savedInstanceState);

	setTitle(R.string.pm_send_actionbar);

	final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.pm_send, null);

	usernameSpinner = (Spinner)layout.findViewById(R.id.pm_send_username);
	recipientEdit = (EditText)layout.findViewById(R.id.pm_send_recipient);
	subjectEdit = (EditText)layout.findViewById(R.id.pm_send_subject);
	textEdit = (EditText)layout.findViewById(R.id.pm_send_text);

	final String initialRecipient;
	final String initialSubject;
	final String initialText;

	if(savedInstanceState != null && savedInstanceState.containsKey(SAVED_STATE_TEXT)) {
		initialRecipient = savedInstanceState.getString(SAVED_STATE_RECIPIENT);
		initialSubject = savedInstanceState.getString(SAVED_STATE_SUBJECT);
		initialText = savedInstanceState.getString(SAVED_STATE_TEXT);

	} else {

		final Intent intent = getIntent();

		if(intent != null && intent.hasExtra(EXTRA_RECIPIENT)) {
			initialRecipient = intent.getStringExtra(EXTRA_RECIPIENT);
		} else {
			initialRecipient = lastRecipient;
		}

		if(intent != null && intent.hasExtra(EXTRA_SUBJECT)) {
			initialSubject = intent.getStringExtra(EXTRA_SUBJECT);
		} else {
			initialSubject = lastSubject;
		}

		initialText = lastText;
	}

	if(initialRecipient != null) {
		recipientEdit.setText(initialRecipient);
	}

	if(initialSubject != null) {
		subjectEdit.setText(initialSubject);
	}

	if(initialText != null) {
		textEdit.setText(initialText);
	}

	final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
	final ArrayList<String> usernames = new ArrayList<>();

	for(RedditAccount account : accounts) {
		if(!account.isAnonymous()) {
			usernames.add(account.username);
		}
	}

	if(usernames.size() == 0) {
		General.quickToast(this, getString(R.string.error_toast_notloggedin));
		finish();
	}

	usernameSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, usernames));

	final ScrollView sv = new ScrollView(this);
	sv.addView(layout);
	setBaseActivityContentView(sv);
}
 
源代码18 项目: NexusDialog   文件: DatePickerController.java
private void refresh(EditText editText) {
    Date value = (Date)getModel().getValue(getName());
    editText.setText(value != null ? displayFormat.format(value) : "");
}
 
源代码19 项目: RedReader   文件: CommentReplyActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {

	PrefsUtility.applyTheme(this);

	super.onCreate(savedInstanceState);

	final Intent intent = getIntent();

	if(intent != null
			&& intent.hasExtra(PARENT_TYPE)
			&& intent.getStringExtra(PARENT_TYPE).equals(PARENT_TYPE_MESSAGE)) {

		mParentType = ParentType.MESSAGE;
		setTitle(R.string.submit_pmreply_actionbar);

	} else {
		mParentType = ParentType.COMMENT_OR_POST;
		setTitle(R.string.submit_comment_actionbar);
	}

	final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.comment_reply, null);

	usernameSpinner = (Spinner)layout.findViewById(R.id.comment_reply_username);
	inboxReplies = (CheckBox)layout.findViewById(R.id.comment_reply_inbox);
	textEdit = (EditText)layout.findViewById(R.id.comment_reply_text);

	if (mParentType == ParentType.COMMENT_OR_POST){
		inboxReplies.setVisibility(View.VISIBLE);
	}

	if(intent != null && intent.hasExtra(PARENT_ID_AND_TYPE_KEY)) {
		parentIdAndType = intent.getStringExtra(PARENT_ID_AND_TYPE_KEY);

	} else if(savedInstanceState != null && savedInstanceState.containsKey(PARENT_ID_AND_TYPE_KEY)) {
		parentIdAndType = savedInstanceState.getString(PARENT_ID_AND_TYPE_KEY);

	} else {
		throw new RuntimeException("No parent ID in CommentReplyActivity");
	}

	final String existingCommentText;

	if(savedInstanceState != null && savedInstanceState.containsKey(COMMENT_TEXT_KEY)) {
		existingCommentText = savedInstanceState.getString(COMMENT_TEXT_KEY);

	} else if(lastText != null && parentIdAndType.equals(lastParentIdAndType)) {
		existingCommentText = lastText;

	} else {
		existingCommentText = null;
	}

	if(existingCommentText != null) {
		textEdit.setText(existingCommentText);
	}

	if(intent != null && intent.hasExtra(PARENT_MARKDOWN_KEY)) {
		TextView parentMarkdown = layout.findViewById(R.id.comment_parent_text);
		parentMarkdown.setText(intent.getStringExtra(PARENT_MARKDOWN_KEY));
	}

	final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
	final ArrayList<String> usernames = new ArrayList<>();

	for(RedditAccount account : accounts) {
		if(!account.isAnonymous()) {
			usernames.add(account.username);
		}
	}

	if(usernames.size() == 0) {
		General.quickToast(this, getString(R.string.error_toast_notloggedin));
		finish();
	}

	usernameSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, usernames));

	final ScrollView sv = new ScrollView(this);
	sv.addView(layout);
	setBaseActivityContentView(sv);
}
 
源代码20 项目: qingyang   文件: LoginDialog.java
private void initView() {
	viewSwitcher = (ViewSwitcher) findViewById(R.id.logindialog_view_switcher);

	loginLoading = (View) findViewById(R.id.login_loading);

	account = (AutoCompleteTextView) findViewById(R.id.login_account);

	password = (EditText) findViewById(R.id.login_password);

	rememberMe = (CheckBox) findViewById(R.id.login_checkbox_rememberMe);

	btn_close = (ImageButton) findViewById(R.id.login_close_button);

	btn_login = (Button) findViewById(R.id.login_btn_login);

	btn_login.setOnClickListener(this);

	btn_close.setOnClickListener(this);

	// 是否显示登录信息
	BaseApplication application = (BaseApplication) getApplication();

	User user = application.getLoginInfo();

	if (user == null || !user.isRememberMe()) {
		return;
	}

	if (!StringUtil.isEmpty(user.getName())) {
		account.setText(user.getName());
		account.selectAll();
		rememberMe.setChecked(user.isRememberMe());
	}
	if (!StringUtil.isEmpty(user.getPassword())) {
		password.setText(user.getPassword());
	}

}