EditText in Android not working/allowing to enter value - java

My EditText element is displaying well in popup window but its not allowing to enter values,I cant type anything inside that edittext element.
here i have attached xml code and screenshot.if you want my main activity class java code too let me know i can add it here.
xml code :
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/background_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="#android:color/darker_gray">
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:id="#+id/texttitle1"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#891800"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appoinment" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
<EditText
android:id="#+id/Easy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
/>
<Button
android:id="#+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="openNewActivity"
android:text="Save" />
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back to Menu" />
</LinearLayout>
</LinearLayout>
</LinearLayout>`

take the input type text noSuggestions and replace it with text

Find the solution:
1.In Manifest file please write windowSoftInputMode :
<activity android:name=".MainActivity"
android:windowSoftInputMode="stateHidden" />
Please put these lines in main LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
3.Please check the document
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Try with below XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="#android:color/darker_gray"
android:orientation="vertical"
android:padding="20dp">
>
<TextView
android:id="#+id/texttitle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appoinment"
android:textColor="#891800"
android:textSize="25dp"
android:textStyle="bold" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
<EditText
android:id="#+id/Easy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions" />
<Button
android:id="#+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="openNewActivity"
android:text="Save" />
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back to Menu" />
</LinearLayout>
</LinearLayout>

In my case, i had accidentally put android:descendantFocusability="blocksDescendants" to the parent layout,which blocks widgets inside this layout focusing. That is why, it was not working :)
If you have this line, please remove and it will work just fine

Related

setting up a tablelayout

I am trying to build a list application for now and I need to align both the button and the text in the same row but as I am extremely new to android studio and Java I am having trouble. any guides I have found are out of date
my code is below
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:strechColumns="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Job 1"
/>
</TableRow>
<ToggleButton
android:id="#+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick=""
android:text="test text"
/>
</TableLayout>
any help would be much appreciated
Try below code inside tag:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Job 1"
/>
<ToggleButton
android:id="#+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick=""
android:text="test text"
/>
/>
Putting your ToggleButton in TableRow will put your items in same row.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:strechColumns="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Job 1"/>
<ToggleButton
android:id="#+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="test text"/>
</TableRow>
</TableLayout>
Other then that If you can achieve same with using List/RecyclerView Adapter if you only need two elements in row,
Using List/RecyclerView is simple approach then TableView. In your Adapter use following XML code for item iterations
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/toggleButton"
android:layout_toStartOf="#+id/toggleButton"
android:layout_alignParentleft="true"
android:layout_alignParentStart="true"
android:text="test "/>
<ToggleButton
android:id="#+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>

Android - Issue with size of EditText in Layout xml

I am having a problem with the layout xml for my fragment... I think it may be because the layout was originally made for just an activity, and then later it was changed to a fragment. It looks like this in my editor:
But in my phone and emulator, it ends up like this:
Can anyone think of a solution for me? I've tried out multiple things but cannot seem to fix it, as i think maybe the rules are a little different when working with fragments? Thank you for all and any help!!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText android:id="#+id/body" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" />
<Button android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Layout file for the activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="130dp"
android:layout_toRightOf="#+id/textView1" >
</FrameLayout>
</LinearLayout>
Just change android:layout_width to match_parent. This will fill up all the available space horizontally.
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" />
<Button android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
For Layout file of activity :
<FrameLayout
android:id="#+id/frame1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="130dp"
android:layout_toRightOf="#+id/textView1" >
</FrameLayout>
You can use the property "ems" to change the size.
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
for your text views and edit views try to match_parent instead of wrapping content
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>

xml layout isn't working for me

I have a lot of info to put on one xml page. Now i got what I want in the positions i want. However instead of fitting all my data on 3 key parts without running into each other, It keeps running into the next TextView. I was wondering how to have it auto adjust.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/back" />
<TextView
android:id="#+id/makeup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginTop="97dp"
android:text="#string/part_section_2" />
<TextView
android:id="#+id/part_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginLeft="19dp"
android:layout_marginTop="38dp"
android:text="put text here for info" />
<TextView
android:id="#+id/part_safety"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_makeup"
android:layout_below="#+id/safety_title"
android:layout_marginTop="28dp"
android:text="put text here for safety" />
<TextView
android:id="#+id/info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="#string/part_section_1" />
<TextView
android:id="#+id/part_makeup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_info"
android:layout_below="#+id/makeup_title"
android:layout_marginTop="33dp"
android:text="put text here for makeup" />
<TextView
android:id="#+id/safety_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/part_makeup"
android:layout_marginTop="48dp"
android:text="#string/part_section_3" />
<TextView
android:id="#+id/part_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:textColor="#b70000"
android:textSize="16sp"
android:text="put text here for part title" />
</RelativeLayout>
would ScrollView work better? and how would switch this from this to ScrollView.
skin is 480x800
density is high(240)
Strings file - http://pastie.org/8534713
Changing to ScrollView (source):
<?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:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- your Button and TextView widgets -->
</RelativeLayout>
</ScrollView>
Edit:
As well as that, try changing your back button XML to this:
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/part_safety"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/back" />
The problem was android:layout_alignParentBottom="true". The bottom ended up not going to the bottom of the page like you had before. The ScrollView cut back on the bottom of the layout.

Linear Layout not visible / Overlapping

I am trying to implement something like an action bar in android 2.2 .
This is my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include
android:id="#+id/header"
layout="#layout/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/dark_button"
>
<Button
android:id="#+id/brand_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/brand_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
/>
<Button
android:id="#+id/car_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/car_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<Button
android:id="#+id/model_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/model_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<Button
android:id="#+id/location_id"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/location_label"
android:textColor="#color/white"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<Button
android:id="#+id/submit"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:text="#string/submit_label"
android:textColor="#color/white"
android:layout_marginTop="10dip"
android:background="#drawable/dark_button"
android:visibility="gone"
/>
<ProgressBar
android:id="#+id/mainProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
And this is my header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo_toyota"
android:layout_weight="1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
I am getting the o/p as
I am wondering what is wrong with the code. I am new to android development. Any help is highly appreciated.
Thanks in advance
Aman Gautam
It is showed in horizontal orientation because it is set by default
In root layout of main.xml
just put android:orientation="vertical"
Instead of rolling out your own code, I highly recommend this open source project, (https://github.com/johannilsson/android-actionbar), I have used it in my own projects and it has worked quite well for me.

Android ImageButton in different screens

In the UI for my application I have 5 ImageButton all is ok on the 3.7" screen but if I have a screen of 2.7", 3.0" or other my UI will not scale and it looks bad. It looks like this:
3,7"
2,7"
How do I make all have a nice look on all screens, just like on the screen 3.7"?
Code: main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/two"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:orientation="vertical"
android:scaleType="fitXY" >
<ImageButton
android:id="#+id/ibTest1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/one" />
</LinearLayout>
</RelativeLayout>
Use a RelativeLayout, and then place a LinearLayout with height wrap_content and put the buttons inside that LinearLayout. Also use dp instead of px for sizes.
P.S. If you post the code of your layout, we can help you better.
EDITED: Now that I can see your code I can show you want I meant with my answer:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/two"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:gravity="center"
android:layout_centerInParent="true" >
<ImageButton
android:id="#+id/ibTest1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
<ImageButton
android:id="#+id/ibTest5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/one" />
</LinearLayout>
</RelativeLayout>
Can you provide some code?
Maybe try add to in xml
android:scaleType="fitXY"
First make image for all
mdpi,hdpi,ldpi
as per their size.
take Lineatlayout in center for Buttons only.
then set property gravity="Center" ;
Make sure your are using dp insted of using 'px'..Its a common cause.
try this add in each imageview in xml
android:adjustViewBounds="true"
android:scaleType="centerCrop"

Categories