cant type in an EditText android - android

I have this xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/horizontalPadding"
android:paddingRight="#dimen/horizontalPadding"
android:paddingTop="#dimen/verticalPadding"
android:paddingBottom="#dimen/verticalPadding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:ems="10" />
</LinearLayout>
</LinearLayout>
When my app is running the keyboard is visible and clickable, but the value of editText doesn't change. how can i resolve it?

If someone is interesed, i resolved using the EditText.requestFocus()

Try to replace android:ems="10" with android:maxEms="10" or android:maxLength="10", I'm not sure, what you want to achieve with this parameter
Hope, this will solve you issue

android:ems="10" is all about width of the view, however you are overriding this setting by layout_width property setting to match_parent.
It looks like you would want two EditTexts to be stretch equally and fill that LinearLayout, so here you wouldn't need ems at all. You would need maxLength instead.
Also note that to stretch those EditTexts you should set their widths to 0dp and set their weight to 1 (or something else. They should be equal).
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:maxLength="10" />
</LinearLayout>

For me, the problem was, I didn't let my PopupWindow be focused. Then I found out that my PopupWindow focusable was by default set to false. So, I try to add 1 new parameter that explicitly tells the PopupWindow is focusable. You can see it in my screenshot below. Previously I didn't pass the false value, only the first three values.
Now, I can type anything in the EditText. This one took a whole day to be resolved. 🤣

Related

TextView/EditText Explain only 1 line

I have created this, with 1 webview and 1 textview (tried also edittext) and a scrollview, but in the preview it explains all lines, when i launch it explain only 1 line. i tried to rmeove scrollview, webview...nothing...how can i do? Thank you
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".ActivityMappa"
tools:showIn="#layout/activity_mappa"
>
<WebView
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="50dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="20dp"
android:id="#+id/webview" />
<EditText
android:id="#+id/testo"
android:layout_width="match_parent"
android:layout_height="126dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:color/transparent"
android:clickable="false"
android:focusable="false"
android:inputType="textMultiLine"
android:lines="10"
android:scrollbars="vertical"
android:text="#string/testonavi_spawn"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
Preview on Android Studio
Preview on my Phone/Emulator
In strings.xml you must escape all ' of testonavi_spawnby \', for example: ...all\'Avamposto...
Take a look into the documentation for String resources.
Edittext height is given as 126dp. You'll not be able to see 30 lines in it. so make the layout_heigh of the edittext as "wrap_content". This will make the edittext dynamic. As the total content is in scrollview, you'll still be able to scroll and see the complete content
Did you try using
android:minLines=10
where 10 is the number of lines you want it to appear.
Since you have set the android:width="match_parent" maybe its going beyond the view change it to android:layout_width="wrap_parent".
Change the code to:
<TextView
android:id="#+id/testo"
android:layout_width="wrap_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:minLines="10"
android:text="#string/testonavi_spawn"
android:textSize="15sp" />
NOTE: Always use a TextView to display the text and EditText to edit any texts.

TextView not wrapping to multiline

I have a TextView inside a LinearLayout which displays only a part of its text without wrapping to a newline and cannot understand why. It doesn't even show the ellipsis somewhere.
The TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="#style/TxtDefault" />
i also tried layout_weight=0 along with layout_height=0 but still no luck. All the siblings inside the LinearLayout have layout_height=wrap_content set.
EDIT
Okay apparently it works when a fixed width is set, but neither with fill_parent nor with match_parent. Is this the expected behaviour?
Per Request the whole layout
Note that inside the FrameLayout is another invisible one, which is rather long
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="#style/ContentBody"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/progress"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_title"
style="#style/TxtTitle" />
<TextView
android:layout_width="410dp"
android:layout_height="wrap_content"
android:text="#string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="#style/TxtDefault" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="410dp"
android:layout_height="wrap_content"
android:id="#+id/progress_bar_view"
android:progress="2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_start"
android:id="#+id/progress_text_view"
style="#style/TxtSecondary" />
</LinearLayout>
</FrameLayout>
if you want to always show text in n lines, just add android:lines="n",
or if it's not work, try to use for your TextView ->
android:textAppearance="?android:attr/textAppearanceLarge"
hope that will help.
The code snippet is wrapping to multiline perfectly. There might be some problem with the IDE, which is not previewing properly. Test on a real device.

Android - Background reset after show/hide views with animation

I am showing and hiding views on a particular actions using some animation, I used LayoutTransition and it seems to work fine except one thing, while the animation is going, the background of some TextViews changes and reset to the default white background!!
Following is the code I am using to apply animation after hide/show.
mRightTransitioner = new LayoutTransition();
mRightTransitioner.setDuration(1000);
vg_rightContainer.setLayoutTransition(mRightTransitioner);
Edited: even without animation i tried, same problem, the background resets once view's position changes
Edited: here how i declared the views in the XML
<LinearLayout
android:id="#+id/ll_req_reasonwrapper"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:gravity="right"
android:orientation="horizontal"
android:visibility="gone" >
<EditText
android:id="#+id/et_req_reasons"
android:layout_width="400dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:gravity="right|center_vertical"
android:inputType="text"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_preasons" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_req_timewrapper"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:gravity="right"
android:orientation="horizontal"
android:visibility="gone" >
<LinearLayout
android:id="#+id/ll_req_endtimewrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/ftv_req_endtime"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:freezesText="true"
android:gravity="right|center_vertical"
android:inputType="numberDecimal"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_endtime" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_req_starttimewrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="50dp" >
<TextView
android:id="#+id/ftv_req_starttime"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:freezesText="true"
android:gravity="right|center_vertical"
android:inputType="numberDecimal"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_starttime" />
</LinearLayout>
</LinearLayout>
for instance: if i hide 'll_req_reasonwrapper', then the LinearLayout 'll_req_timewrapper' moves up, then the backgrounds of the textViews like 'ftv_req_starttime' becomes white!!
Please help.
Edited Answer:
if your are using linear layout then if the child is not being displayed, it is not going to be laid out and not going to be the part of the measurements ( as it looks like ). I recommend to use the RelativeLayout.
You can try
android:background="#null"
for your buttons. if your are using some custom class for button then add
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
for this specific views.
Need more code. The fact that disabling the LayoutTransition does not solve your issue, means that the animation is not the issue.
How do you reinstantiate child views or populate your view. Are you removing views with setVisibility(View.GONE) and then setting them back with setVisibility(View.VISIBLE)
OR
Are you removing childAt(i) and then dynamically adding custom views
I'm sorry I couldnt add a comment since I dont have the reputation for that but I think I am able to answer your question if you post more code.

My Edittext getting extended while typing the text

My Edittext its getting extend automatically while typing the text,Dont know what mistake i have done, please check my screen shot for exactly what my issue is, help me to find a solution. Thanks in advance.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="#+id/oldpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectdate"
android:ems="10"
android:hint="#string/oldpass"
android:inputType="textPassword"
android:paddingLeft="5dip" >
</EditText>
</LinearLayout>
</LinearLayout>
check my screen shot for how its extend while typing
your height and weight are Wrap_content as it adjust upon the length of the text you given
change that to fixed dp length
android:layout_width="150dp"
android:layout_height="wrap_content"
It is due to this layout definition: android:layout_width="wrap_content"
You're basically telling that your EditText should fit the content. That means it will have a default size, but once you're typing in it and making it wider, it will extend according to the text it has inside.
You probably want to use android:layout_width="match_parent" to fit it to the screen, or play around with android:layout_weight to make it proportional to other layout items.
Set WEIGHT property of your edittext it will not extended.
android:layout_width="0dp"
android:layout_weight="1"
Try this
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center" >
<EditText
android:id="#+id/oldpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectdate"
android:ems="10"
android:hint="#string/oldpass"
android:inputType="textPassword"
android:paddingLeft="5dip" >
</EditText>
</LinearLayout>
I believe your issue is you are setting the layout_width of the EditText as wrap_content

Making EditText and Button same height in Android

I have an EditText and a Button in my LinearLayout and I want to align them closely together so they see seem to belong together (edittext + micButton for speech input).
Now they don't have the same height and they aren't really aligned well (Button seems to be a little lower than the EditText). I know I can apply a negative margin like -5dp to make them come closer together, but is there perhaps a better way to do this?
Set them in a specific container/layout so that they will automatically have the same height and no margin between them?
Using relative layout you can stretch a view depending upon another views size without knowing the exact size of the other view.
Here is the code :
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:text="button"
android:id="#+id/but"/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/but"
android:layout_alignBottom="#id/but"
android:layout_alignTop="#id/but"
/>
</RelativeLayout>
Check this link for reducing space between views :
https://groups.google.com/forum/?fromgroups#!topic/android-developers/RNfAxbqbTIk
Hmm, don't know why people bother so much with tables. Since the both Views are within a LinearLayout (presumable orientation=Horizontal), this command should center both within the layout:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
Note: Since EditTexts and Buttons may orient their text slightly differently, you may have to do some tweaking (by changing margins or padding) to get the text to align properly.
I hope this solution might help for your scenario...Here is the code..
<RelativeLayout
android:id="#+id/rlLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal"
android:padding="3dp" >
<EditText
android:id="#+id/etId"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#c8c8c8"
android:hint="Edittext"
android:paddingLeft="20dip"
android:paddingRight="10dip"
android:textColor="#000000" />
<RelativeLayout
android:id="#+id/rlLayoutid"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignRight="#+id/etId" >
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:layout_marginTop="10dp"
android:background="#drawable/calender" />
</RelativeLayout>
</RelativeLayout>
# Daniel Here You can use layout weight and weight sum
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:weight_sum=2
>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=1
android:text="button"
android:id="#+id/but"/>
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=1
/>
</LinearLayout>
Android tries to automatically level everything off of the text and not the buttons themselves.
Took me forever to finally figure it out. Its really simple. Should fix it.
myButton.setGravity(Gravity.CENTER_VERTICAL);
or if they are in a row.. attach the buttons to a table row, then.
myTableRow.setGravity(Gravity.CENTER_VERTICAL);

Categories

Resources