Java Code Examples for android.widget.EditText#setText()

The following examples show how to use android.widget.EditText#setText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorView.java    From Hillffair17 with GNU General Public License v3.0 6 votes vote down vote up
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);
            }

        }
    }

}
 
Example 2
Source File: AccountsSetManager.java    From fingen with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: EditListNameFragment.java    From sqlitemagic with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 4
Source File: AnagramsActivity.java    From jterm-cswithandroid with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 5
Source File: MainActivity.java    From OpenYOLO-Android with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 6
Source File: CloudProfileConfigurationDialogFragment.java    From SensorTag-CC2650 with Apache License 2.0 5 votes vote down vote up
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);
    }

}
 
Example 7
Source File: AnnotationsActivity.java    From listmyaps with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: HyperTextEditor.java    From YCCustomText with Apache License 2.0 5 votes vote down vote up
/**
 * 在特定位置插入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();
	}
}
 
Example 9
Source File: SettingsActivity.java    From MyOwnNotes with GNU General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example 10
Source File: CarTableDataAdapter.java    From SortableTableView with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: SecondNameActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 12
Source File: ApSsidConfigFragment.java    From freeiot-android with MIT License 5 votes vote down vote up
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);
}
 
Example 13
Source File: RenameFileDialogFragment.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 14
Source File: IssueEditorActivity.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
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);
}
 
Example 15
Source File: PMSendActivity.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example 16
Source File: DatePickerController.java    From NexusDialog with Apache License 2.0 4 votes vote down vote up
private void refresh(EditText editText) {
    Date value = (Date)getModel().getValue(getName());
    editText.setText(value != null ? displayFormat.format(value) : "");
}
 
Example 17
Source File: EditPagePort.java    From MyHearts with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 18
Source File: IssueEditorActivity.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
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);
}
 
Example 19
Source File: CommentReplyActivity.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example 20
Source File: LoginDialog.java    From qingyang with Apache License 2.0 3 votes vote down vote up
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());
	}

}