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

The following examples show how to use android.widget.EditText#setTag() . 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: HyperTextEditor.java    From YCCustomText with Apache License 2.0 6 votes vote down vote up
/**
 * 添加生成文本输入框
 * @param hint								内容
 * @param paddingTop						到顶部高度
 * @return
 */
private EditText createEditText(String hint, int paddingTop) {
	EditText editText = new DeletableEditText(getContext());
	LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	editText.setLayoutParams(layoutParams);
	editText.setTextSize(16);
	editText.setTextColor(Color.parseColor("#616161"));
	editText.setCursorVisible(true);
	editText.setBackground(null);
	editText.setOnKeyListener(keyListener);
	editText.setOnFocusChangeListener(focusListener);
	editText.addTextChangedListener(textWatcher);
	editText.setTag(viewTagIndex++);
	editText.setPadding(editNormalPadding, paddingTop, editNormalPadding, paddingTop);
	editText.setHint(hint);
	editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, rtTextSize);
	editText.setTextColor(rtTextColor);
	editText.setHintTextColor(rtHintTextColor);
	editText.setLineSpacing(rtTextLineSpace, 1.0f);
	HyperLibUtils.setCursorDrawableColor(editText, cursorColor);
	return editText;
}
 
Example 2
Source File: PinViewBaseHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Generate a PinBox {@link EditText} with all attributes to add to {@link PinView}
 *
 * @param i index of new PinBox
 * @param inputType inputType to new PinBox
 * @return new PinBox
 */
EditText generatePinBox(int i, int inputType) {
    EditText editText = (EditText) LayoutInflater.from(getContext()).inflate(R.layout.partial_pin_box, this, false);
    int generateViewId = PinViewUtils.generateViewId();
    editText.setId(generateViewId);
    editText.setTag(i);
    if (inputType != -1) {
        editText.setInputType(inputType);
    }
    setStylePinBox(editText);

    editText.addTextChangedListener(this);
    editText.setOnFocusChangeListener(this);
    pinBoxesIds[i] = generateViewId;

    return editText;
}
 
Example 3
Source File: PinViewBaseHelper.java    From PinView with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a PinBox {@link EditText} with all attributes to add to {@link PinView}
 *
 * @param i index of new PinBox
 * @param inputType inputType to new PinBox
 * @return new PinBox
 */
EditText generatePinBox(int i, int inputType) {
    EditText editText = (EditText) LayoutInflater.from(getContext()).inflate(R.layout.partial_pin_box, this, false);
    int generateViewId = PinViewUtils.generateViewId();
    editText.setId(generateViewId);
    editText.setTag(i);
    if (inputType != -1) {
        editText.setInputType(inputType);
    }
    setStylePinBox(editText);

    editText.addTextChangedListener(this);
    editText.setOnFocusChangeListener(this);
    pinBoxesIds[i] = generateViewId;

    return editText;
}
 
Example 4
Source File: CompassFragment.java    From TextFiction with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
	editCommand = new EditText(getActivity());
	editCommand.setSingleLine(true);
	try {
		editCommand.setText(v.getTag().toString());
		editCommand.setTag(v);
	}
	catch (Exception e) {
		Log.w(getClass().getName(), e); // ?!
	}
	AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
	builder.setView(editCommand);
	builder.setTitle(R.string.title_edit_direction);
	builder.setPositiveButton(android.R.string.ok, this);
	builder.show();
	return true;
}
 
Example 5
Source File: Pinview.java    From Pinview with MIT License 5 votes vote down vote up
/**
 * Takes care of styling the editText passed in the param.
 * tag is the index of the editText.
 *
 * @param styleEditText
 * @param tag
 */
private void generateOneEditText(EditText styleEditText, String tag) {
    params.setMargins(mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2);
    filters[0] = new InputFilter.LengthFilter(1);
    styleEditText.setFilters(filters);
    styleEditText.setLayoutParams(params);
    styleEditText.setGravity(Gravity.CENTER);
    styleEditText.setCursorVisible(mCursorVisible);

    if (!mCursorVisible) {
        styleEditText.setClickable(false);
        styleEditText.setHint(mHint);

        styleEditText.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                // When back space is pressed it goes to delete mode and when u click on an edit Text it should get out of the delete mode
                mDelPressed = false;
                return false;
            }
        });
    }
    styleEditText.setBackgroundResource(mPinBackground);
    styleEditText.setPadding(0, 0, 0, 0);
    styleEditText.setTag(tag);
    styleEditText.setInputType(getKeyboardInputType());
    styleEditText.addTextChangedListener(this);
    styleEditText.setOnFocusChangeListener(this);
    styleEditText.setOnKeyListener(this);
}
 
Example 6
Source File: EditorView.java    From Hillffair17 with GNU General Public License v3.0 5 votes vote down vote up
private EditText createEditText(String hint, int Padding) {
    EditText editText = (EditText) inflater.inflate(R.layout.item_edittext, null);
    editText.setTag(viewTag++);
    editText.setOnFocusChangeListener(focusChangeListener);
    editText.setOnKeyListener(keyListener);
    editText.setPadding(dip2px(EDIT_PADDING_TOP), Padding, dip2px(EDIT_PADDING_TOP), 0);
    editText.setHint(hint);
    return editText;
}
 
Example 7
Source File: EditorView.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
private EditText createEditText(String hint, int Padding) {
    EditText editText = (EditText) inflater.inflate(R.layout.item_edittext, null);
    editText.setTag(viewTag++);
    editText.setOnFocusChangeListener(focusChangeListener);
    editText.setOnKeyListener(keyListener);
    editText.setPadding(dip2px(EDIT_PADDING_TOP), Padding, dip2px(EDIT_PADDING_TOP), 0);
    editText.setHint(hint);
    return editText;
}
 
Example 8
Source File: EditCredentialsActivity.java    From WiFiAfterConnect with Apache License 2.0 5 votes vote down vote up
private void addField (HtmlInput field) {
Log.d(Constants.TAG, "adding ["+field.getName() + "], type = [" + field.getType()+"]");

  	TextView labelView =  new TextView(this);
  	labelView.setText(field.getName());
  	int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, (float) 8, getResources().getDisplayMetrics());
  	labelView.setTextSize (textSize);
  	
  	EditText editView = new EditText(this);
  	editView.setInputType(field.getAndroidInputType());
  	editView.setText (field.getValue());
  	editView.setTag(field.getName());
  	editView.setFocusable (true);
  	
  	edits.add(editView);
  	
  	editView.setOnEditorActionListener(new EditText.OnEditorActionListener() {
	@Override
	public boolean onEditorAction(TextView v, int actionId,	KeyEvent event) {
  			if (actionId == EditorInfo.IME_ACTION_DONE) {
  				onSaveClick(v);
  			}
  			return false;
	}

  	});    	
  	
  	TableRow row = new TableRow (this);
	fieldsTable.addView (row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));

  	TableRow.LayoutParams labelLayout = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);
  	int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 5, getResources().getDisplayMetrics());
  	labelLayout.setMargins(margin, margin, margin, margin);
  	row.addView(labelView, labelLayout);
  	TableRow.LayoutParams editLayout = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.WRAP_CONTENT);
  	row.addView(editView, editLayout);
  }
 
Example 9
Source File: WifiAuthenticatorActivity.java    From WiFiAfterConnect with Apache License 2.0 5 votes vote down vote up
private void addField (HtmlInput field) {
Log.d(Constants.TAG, "adding ["+field.getName() + "], type = [" + field.getType()+"]");

  	TextView labelView =  new TextView(this);
  	labelView.setText(field.getName());
  	int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, (float) 8, getResources().getDisplayMetrics());
  	labelView.setTextSize (textSize);
  	
  	EditText editView = new EditText(this);
  	editView.setInputType(field.getAndroidInputType());
  	editView.setText (field.getValue());
  	editView.setTag(field.getName());
  	editView.setFocusable (true);
  	
  	edits.add(editView);
  	
  	editView.setOnEditorActionListener(new EditText.OnEditorActionListener() {
	@Override
	public boolean onEditorAction(TextView v, int actionId,	KeyEvent event) {
  			if (actionId == EditorInfo.IME_ACTION_DONE) {
  				onAuthenticateClick(v);
  			}
  			return false;
	}
  	});    	
  	
  	TableRow row = new TableRow (this);
	fieldsTable.addView (row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));

  	TableRow.LayoutParams labelLayout = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);
  	int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 5, getResources().getDisplayMetrics());
  	labelLayout.setMargins(margin, margin, margin, margin);
  	row.addView(labelView, labelLayout);
  	TableRow.LayoutParams editLayout = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.WRAP_CONTENT);
  	row.addView(editView, editLayout);
  	
  }
 
Example 10
Source File: RichAdapter.java    From RichEditor with Apache License 2.0 4 votes vote down vote up
/**
 * 文本编辑器
 */
private void bindEditComponent(RecyclerView.ViewHolder holder, final int pos, final
RichModel item) {
    if (holder instanceof EditHolder) {
        final EditText mEdit = ((EditHolder) holder).mEt;
        mEtHolder.add(mEdit);
        if (index == pos) {
            mCurEdit = ((EditHolder) holder).mEt;
            mEdit.setFocusable(true);
            mEdit.setFocusableInTouchMode(true);
            mEdit.requestFocus();
        } else {
            mEdit.setFocusable(false);
        }
        ((EditHolder) holder).textWatcher.updatePosition(pos);
        ((EditHolder) holder).filter.updatePosition(pos);
        mEdit.setTextSize(Const.DEFAULT_TEXT_SIZE);
        if (item.isParagraphStyle) {
            SpannableStringBuilder spannableString = new SpannableStringBuilder(item.source);
            for (Object obj : item.paragraphSpan.mSpans) {
                if (obj instanceof AbsoluteSizeSpan) {
                    AbsoluteSizeSpan sizeSpan = (AbsoluteSizeSpan) obj;
                    mEdit.setTextSize(sizeSpan.getSize());
                    continue;
                }
                spannableString.setSpan(obj, 0, item.source.length(), Spanned
                        .SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            mEdit.setText(spannableString);
            paragraphHelper.handleTextStyle(mEdit, item.paragraphSpan.paragraphType);
        } else {
            mSpanString.clear();
            mSpanString.clearSpans();
            mSpanString.append(item.source);
            if (isEnter) {
                for (SpanModel span : item.getSpanList()) {
                    mSpanString.setMultiSpans(span.mSpans, span.start, span.end, Spanned
                            .SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
            mEdit.setText(mSpanString);
            paragraphHelper.handleTextStyle(mEdit, -1);
        }
        mEdit.setSelection(item.curIndex);
        //mEdit.setSelection(item.source.length());
        mEdit.setHint(item.hint);
        mEdit.setTag(pos);
        //只存在一个EditText的时候,点击区域太小,所以只有一个的时候,将MinHeight设为500
        if (index == pos && index < 2 && index == mData.size() - 1) {
            mEdit.setMinHeight(DensityUtil.dp2px(mContext, 500));
        } else {
            mEdit.setMinHeight(DensityUtil.dp2px(mContext, 0));
        }
    }

}
 
Example 11
Source File: AddInfoAty.java    From Huochexing12306 with Apache License 2.0 4 votes vote down vote up
private void initViews() {
	btnFrom = (Button) findViewById(R.id.from);
	btnFrom.setOnClickListener(this);
	btnTo = (Button) findViewById(R.id.to);
	btnTo.setOnClickListener(this);
	btnTrainNum = (Button) findViewById(R.id.trainNum); // 车次
	btnTrainNum.setOnClickListener(this);
	etDate = (EditText)findViewById(R.id.date);
	btnDate = (Button) findViewById(R.id.btnDate); // 选择乘车日期
	btnDate.setOnClickListener(this);
	btnOK = (Button) findViewById(R.id.ok);
	btnOK.setOnClickListener(this);
	etTravelName = (EditText) findViewById(R.id.travelName);
	etTime = (EditText) findViewById(R.id.time);
	
	btnFrom.setText(setSP.getLastFromStationKey());
	btnTo.setText(setSP.getLastToStationKey());
	// 取得当前日期
	Calendar c = Calendar.getInstance(Locale.getDefault());
	c.setTimeInMillis(System.currentTimeMillis());
	intYear = c.get(Calendar.YEAR);
	intMonth = c.get(Calendar.MONTH);
	intDay = c.get(Calendar.DAY_OF_MONTH);
	String strDate = TimeUtil.getDFormat().format(c.getTime());
	etDate.setText(strDate + "  " + TimeUtil.getWeek(c.getTime()));
	etDate.setTag(strDate);
	
	if (this.getIntent().getStringExtra(TRAIN_NUM) != null){
		strTrainNum = this.getIntent().getStringExtra(TRAIN_NUM);
		btnFrom.setText(this.getIntent().getStringExtra(START_STATION));
		btnTo.setText(this.getIntent().getStringExtra(END_STATION));
		intDataSource = this.getIntent().getIntExtra(DATA_SOURCE, DATA_FROM_OFFINE_DB);
		
		if (intDataSource == DATA_FROM_OFFINE_DB){
			SimpleDialogFragment
			.createBuilder(
					AddInfoAty.this,
					getSupportFragmentManager())
			.setCancelable(false)
			.setRequestCode(REQUET_SET_TRAVEL_BRIEF_OF_DATA_FROM_OFFLINE_DB)
			.setTitle("提示")
			.setMessage("检测到您采用离线数据快速添加数据,为保证数据准确性请您手动进行车次选择"+SF.TIP)
			.setPositiveButtonText("确定")
			.show();
		}
		String strStartTime = getIntent().getStringExtra(EXTRA_START_TIME);
		if (!TextUtils.isEmpty(strStartTime)){
			try {
				Date date1 = TimeUtil.getDFormat().parse(strStartTime);
				strStartTime = TimeUtil.getDFormat().format(date1);
				etDate.setText(strStartTime + " " + TimeUtil.getWeek(strStartTime));
				etDate.setTag(strStartTime);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		getTrains();
	}
}