EditText not accepting an input - android

I have 2 EditTexts on my screen. The first one works fine, but the second doesn't. I click on the first EditText and can enter text. But click on the second EditText and any input continues to appear in the first EditText.
Looking at other questions on the subject, there is talk of using setFocus and having onClick listeners for the EditText fields. Is this correct?
I have another app which had several screens with multiple EditTexts and never had to do this.
This is my current XML:
<TextView
android:id="#+id/namLabel"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name" />
<EditText
android:id="#+id/namTxt"
android:layout_below="#id/namLabel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:minWidth="200sp" />
<TextView
android:id="#+id/numLabel"
android:layout_alignParentLeft="true"
android:layout_below="#id/namTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20sp"
android:paddingRight="10sp"
android:text="#string/units" />
<EditText
android:id="#+id/numTxt"
android:layout_toRightOf="#id/numLabel"
android:layout_alignBaseline="#id/numLabel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="numberDecimal"
android:minWidth="50sp" />
This is all the relevant code I have in the onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_game);
namText = (EditText) findViewById(R.id.namTxt);
numText = (EditText) findViewById(R.id.numTxt);
Please don't tell me I have to add a whole load of onClickListeners for these fields?

I found the problem. I just had to add the setFocusableInTouchMode to both EditText's:
android:focusableInTouchMode="true"
I didn't do that in my last app, so no idea why I have to now.

You don't need to add any listeners or setFocus. The only "strange" thing I see is that you are not wrapping your xml in a RelativeLayout. It should work just fine, just tested it.

Related

Phone number inside TextView become underscored but not clickable

I have complicated XML file. Here is a piece:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="#string/tel"
style="#style/AppTheme.TextInputLayout"
android:layout_marginBottom="#dimen/space_high">
<android.support.design.widget.TextInputEditText
android:id="#+id/point.j_tel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/AppTheme.TextInputEditText"/>
</android.support.design.widget.TextInputLayout>
<ImageButton
android:layout_gravity="center"
android:id="#+id/point.telEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tab_icon_edit"/>
</LinearLayout>
I'm trying to make phone numbers inside android:id="#+id/point.j_tel" clickable. I tried android:autoLink="all", android:autolink="phone", android:linksClickable="true". But this only led phone numbers become underscored and semi tranceparent but not clickable . I also tried this inside my Java code:
cameraManager = new CameraManager(this);
etNotice = findViewById(R.id.point_c_notice);
getValidations().add(new TextEmptyValidation(this, etNotice));
etNotice.addTextChangedListener(getLastValidation());
tiAddress = findViewById(R.id.point_c_address);
tiTel = findViewById(R.id.point_j_tel);
tiTel.setAutoLinkMask(Linkify.PHONE_NUMBERS);
tiTel.setMovementMethod(new ScrollingMovementMethod());
I tried a lot of things during two days, but nothing helps and I almost gave up.
Maybe somebody has any ideas?
Why do you need to click on EditText to make the call? It should be TextView or add calling button beside the EditText

Done key not showing up on keyboard

I am making an Android app and want the done key to show up on the keyboard when the user is typing into the keyboard.
This is the XML code for the EditText:
<EditText
android:id="#+id/answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:layout_marginBottom="113dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:imeOptions="actionDone"
/>
I thought that adding the android:imeOptions="actionsDone would have the done button appear, but instead the enter button is there and when it is pressed, a new line is created in the EditText. What is the issue?
You will not get done by adding imeOptions.
Add the below attribute to your EditText:
android:singleLine="true"
This will make your EditText a single line and you will see the Done button if that is the only EditText or last EditText. If there are multiple EditText items, then you will see Next button.

EditText gaining focus but my typing doesn't append

I have an EditText and have a hint. When I tap on the EditText, the keyboard appears, though, as I type neither the hint goes away nor my typing goes into view. It's like my input is going to /dev/null. My EditText is inside a ListView cell, if it helps. Here is my layout:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#00000000"
android:id="#+id/aboutView"
android:layout_gravity="center_horizontal|bottom"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headerFrame"
android:layout_marginTop="12dp"
android:gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:textSize="14dp"
android:layout_marginBottom="12dp"
android:hint="Tell something about yourself..." />
Why can this be?
Found the solution here: EditText in Listview loses focus when pressed on Android 4.x
I don't know the exact reason, but I wasn't the only one suffering from EditText focus problems when inside a ListView. I've added android:windowSoftInputMode="adjustPan" to my activity in manifest file and the problem went away.

Adding TextView dynamically to an layout for a messaging app

I am trying to build a simple messaging app. which have one EditText and one Button at the bottom of the screen. when someone enters text and click the send button the entered text should appear as a msg on the top of the (EditText and Button). If the user have sent lots of msgs unable to fit to fit in the screen, the scrollbar for scrolling and viewing msgs should automatically appear.
I have made the layout as
<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">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:id="#+id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#android:color/black"
android:onClick="sendMessage"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:hint="#string/edit_message"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/button"
android:layout_toStartOf="#+id/button"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
and Java code to fetch the msg is
public void sendMessage(View view) {
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
}
I need someone to guide me how to proceed after this.
I want the msg to appear above each time. Any help or suggestion will be great helpful for me.
For a simpler solution, you might want to try using one textview. You just keep adding the new messages to it.
I would create my own custom layout just so that different combinations are possible (e.g timestamps, emojis). Basically a custom layout which draws all your different items on there.
You can use a custom listView with 9patch images.

Android issue with EditText object

I have an activity where the user is presented with a list of edit texts. The problem is, as soon as the activity starts, the virtual keyboard is brought up right away for the first edit text. I don't want this to happen as there is a spinner before this edit text, and often I've found that popping up the keyboard like this makes the user forget about that previous spinner.
Here's the relevant code:
<Spinner
android:id="#+id/event_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30px"
android:prompt="#string/location_prompt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Name: " />
<EditText
android:id="#+id/event_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity Type: " />
<Spinner
android:id="#+id/event_type"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address: " />
<EditText
android:id="#+id/event_address"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Summary: activity with an EditText starts, and the virtual keyboard automatically pops up. I don't want it to do this unless the user presses on the edit text.
Thanks for any help.
The EditText is automatically set to focus so you need to put android:focusable="false" or editText.setFocusable(false) to prevent the EditText to be focused while the spinner is visible. You could also try editText.setSelected(false).
Try changing your spinner XML to this:
<Spinner
android:layout_marginTop="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/event_location"
android:prompt="#string/location_prompt">
<requestFocus />
</Spinner>
Also try to do for each EditText:
android:focusable="false"
android:focusableInTouchMode="false"
Look at this post: Stop EditText from gaining focus at Activity startup
This is how it works for me:
to make sure the edit text wont get focus on startup:
In xml set the focusable attribute of the EditText to false:
android:focusable="false"
2. in order to make the EditText focusable again after startup:
set the focusable attribute from code in the oncreate() method of the wanted activity after the setContent() method:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main_view);
....
EditText et = (EditText) findViewById(R.id.et_notes);
et.setFocusable(true);
et.setFocusableInTouchMode(true);
...
}

Categories

Resources