I was wondering if there is a way to group EditText in a way that you can only traverse among a group of them.
The problem is that I rely on reaching the end of the first group and use EditorInfo.IME_ACTION_DONE in order to trigger a certain action.
The inner group of EditTexts is inside a LinearLayout.
Put the text boxes in a layout(linear or relative) only those EditText which you want to make a group. layout will act as group. Add this on your every Edittext xml--
android:maxLines="1"
if it does not works the you can handle focus.
Focus Handling
Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer.
Change default behaviour of directional navigation by using following XML attributes:
android:nextFocusDown="#+id/.."
android:nextFocusLeft="#+id/.."
android:nextFocusRight="#+id/.."
android:nextFocusUp="#+id/.."
Besides directional navigation you can use tab navigation. For this you need to use
android:nextFocusForward="#+id/.."
To get a particular view to take focus, call
view.requestFocus()
To listen to certain changing focus events use a View.OnFocusChangeListener
Keyboard button
You can use android:imeOptions for handling that extra button on your keyboard.
Additional features you can enable in an IME associated with an editor to improve the integration with your application. The constants here correspond to those defined by imeOptions.
The constants of imeOptions includes a variety of actions and flags, see the link above for their values.
Value example
ActionNext :
the action key performs a "next" operation, taking the user to the next field that will accept text.
ActionDone :
the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.
Code example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:imeOptions="actionNext"
android:singleLine="true"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:layout_marginTop="24dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:ems="10" />
</RelativeLayout>
If you want to listen to imeoptions events use a TextView.OnEditorActionListener.
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
Edit:
For dynamic edittext you can try..
EditText etCurrent;
Set an OnTouchlistener on each EditText:
valueET.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (etCurrent != null) {
if (etCurrent.getId() != v.getId()) {
if (!check(etCurrent.getId())) {
etCurrent.setSelection(0,
etCurrent.getText().toString().length());
return true;
} else {
etCurrent = (EditText) v;
}
}
} else {
etCurrent = (EditText) v;
}
}
return false;
}
});
Related
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/customedittext"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<EditText
android:id="#+id/answer1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="#font/timeandspace"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:hint="1."
android:background="#color/transparent"
android:inputType="text"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textColor="#color/colormain"
android:textSize="25sp" /></LinearLayout>
How can I wrap the text vertically or set a maximum width of my text without using android:inputType="textmultiline"?
reason if why i didnt want that input type because i am using the Enter in keyboard to submit the text and not to add line. Hope someone can help me :)
And, how can I prevent automatically showing keyboard and focus to edittext at the start of activity?
Thanks a lot <3
This will not add a line:
reason if why i didnt want that input type because i am using the
Enter in keyboard to submit the text and not to add line
answer1.setOnEditorActionListener(new OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (event.getAction() == KeyEvent.KEYCODE_ENTER)
{
// Do whatever you wanna do on "Enter"
return true;
}
return false;
}
});
And, how can I prevent automatically showing keyboard and focus to
edittext at the start of activity?
Remove any EditText.requestFocus() call in your activity.
In my application I have EditText and Button and for this editText I set actionDone for imeOption.
My EditText code :
<EditText
android:id="#+id/infoSerialFrag_rememberSwitchText"
android:layout_width="#dimen/size30"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/infoSerialFrag_rememberSwitch"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:hint="7"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="3"
android:maxLines="1"
android:textSize="#dimen/font11" />
When open keyboard show me Done in keyboard.
For Button I set one method.
I want when click on Done from keyboard, work me such as onClickListener for my Button.
My mean is : when click on Done from keyboard, call method in button.setOnClickLiostener{...}
How can I it? please help me
Use below code
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(EditText v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
view.performClick();
return true;
}
return false;
}
});
View is the button view name. You need to call performClick() method. this will execute the code which is available in onclick() call back method. Hope that answers your question
I have an EditText inside of a ScrollView which is pre-filled with a dynamic amount of text. It could be one line or 50 or more. At this point, the EditText is uneditable and the text is shown just fine. However, when I press a button to make the edit text editable, the entire contents of the EditText are thrown into one very long, horizontally scrolling line.
You can see exactly what I'm talking about here:
https://zippy.gfycat.com/GenerousBigHerring.webm
How can I prevent this from happening? I've been screwing around with this for a while now. I've tried setting lines and maxLines, etc, but I can't figure it out.
Edit:
This is my current ScrollView/EditText:
<ScrollView
android:id="#+id/result_text_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/result_title_text"
android:layout_above="#+id/result_bottom_sheet"
android:layout_marginTop="20dp"
android:padding="5dp">
<EditText
android:id="#+id/extracted_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:padding="15dp"
tools:text="Hello, World"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="#dimen/extracted_text_size"
android:textIsSelectable="true"
android:inputType="none"
/>
</ScrollView>
From code, here's what I'm doing to to enable/disable editing:
#Override
public void enableTextEditing() {
mExtractedText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
mExtractedText.setOnKeyListener(this);
}
#Override
public void disableTextEditing() {
mExtractedText.setInputType(InputType.TYPE_NULL);
mExtractedText.setOnKeyListener(null);
}
#Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
//All this does is call the View methods to disable text editing
//and close the keyboard.
mPresenter.doneEditingButtonPressed();
return true;
}
return false;
}
Add android:lines , android:minLines and android:maxLines to your EditText view
Also change android: inputType = "textMultiline"
You can add android:scrollbars="vertical" to your EditText as well if you wish
I'm trying to stop the progress of the seek bar unless the user started below progress(10), this ensures the user actually has to slide it, thus avoiding accidental activation. I've tried this so far and it looks like it'd work, however the slide bar can still be moved from anywhere (progress(0) up to progress(100).
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
private Boolean isInRange = true;
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (seekBar.getProgress() > 95) {
((MainActivity)getActivity()).currentOrder = null;
((MainActivity)getActivity()).showMain();
} else {
seekBar.setProgress(0);
isInRange = false;
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
if (seekBar.getProgress() < 10) {
isInRange = true;
} else {
seekBar.setProgress(0);
isInRange = false;
}
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(!isInRange) {
seekBar.setProgress(0);
}
}
});// Set on seek bar change listener
just in case you need it, here's the XML code of the seekbars container:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorFocus"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/seperator_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
android:orientation="horizontal" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/btn_delivery_disabled"
android:padding="16dp"
android:layout_margin="16dp">
<SeekBar
android:id="#+id/seek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:max="100"
android:progressDrawable="#android:color/transparent"
android:thumb="#mipmap/ic_slide" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/delivered"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Large"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:id="#+id/textView" />
</RelativeLayout>
</LinearLayout>
The setProgress is absolute value, not relative to where your progress currently is. What you actually are doing is essentially resetting the progress to 0 any time when the touch is not within the first 10 percent of the SeekBar, not within 10 percent of where the progress is. That, of course, is assuming that you can not provided max attribute, in which case the max value is set at 100.
So, you need to adjust your code to read current value, then compare it to current and see if it is within 10 percent. I would also recommend to keep track of starting position and end position rather then only having a simple boolean value to track it. Then you have to evaluate the value in relation to current position.
I have problem with handling Touch events inside my TextView on Android 2.3.3. I've got Activity implements OnTouchListener with method
main.java
public boolean onTouchEvent(MotionEvent event) {
if(event.getPointerCount()==1){
textView.setTextSize(mRatio+13);
mRatio++;
Log.d("TouchEvent", "one touch !");
}
if (event.getPointerCount() == 2) {
some code...
}
return true;
}
and my layout(only part of it):
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.0"
android:fadingEdge="none"
android:background="#color/white">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp">
<!-- TEXT EMAIL : -->
<TextView
android:id="#+id/mail_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="15sp"
android:autoLink="web"
android:clickable="true"
android:textColor="#color/mailtext"
android:scrollbars = "vertical"/>
</LinearLayout>
</LinearLayout>
When i 'clicked' anywhere outside my textBox(for example on header or footer), the Touch event trigger, font get bigger. I assume than the problem is probably because scrollbars. But when I cut off android:scrollbars = "vertical" bar just disappear.
This textView usually contain a lots of text.
How to proper fire onTouchEvents inside this textView.
Edit:
when this textView is small my touchEvent work until i get text so big, than the scrollBar is needed. Then all touch event get overrided and You can only scroll textView. No TouchEvent is called.
I handle the problem in other way. OnTouchEvent didn't worked with my TextView so I Override dispatchTouchEvent. It's far more better to performe actions "onTouch".Scrollbar is working and I can add my multitouch events on the whole screen. It's look like:
#Override
public boolean dispatchTouchEvent(MotionEvent motionEvent){
Log.v("NotificationActivity.dispatchTouchEvent()", "got touch");
if (motionEvent.getPointerCount() == 2) {
Log.v("touch", "multi touch !");
int action = motionEvent.getAction();
int pureaction = action & MotionEvent.ACTION_MASK;
// some actions ...
}
switch (motionEvent.getAction()){
case MotionEvent.ACTION_DOWN:{
//Keep track of the starting down-event.
Log.v("akcjaa","down");
// some actions ...
break;
}
case MotionEvent.ACTION_UP:{
//Consume if necessary and perform the fling / swipe action
//if it has been determined to be a fling / swipe
Log.v("akcjaa","up");
break;
}
}
return super.dispatchTouchEvent(motionEvent);
}
I am assuming your TextView is inside some kind of ScrollView or Scrollable container, right?
Then you will face this issue. Android does not like his apples and pears mixed, you should not be trying to receive "onTouch" events that are being consumed by the father layout on top of the view.
I guess you could:
a) Switch to a onClickListener on your TextView
b) Override your parent view layout touch handler to bleed the touch down to its childs. This is not really 100% recommended, and could cause unwanted behaviour.
Sorry if i cannot be of more help.