Issue with EditText in Listview softkeyboard - android

I have a Listview with row layout contains two textviews and a edittext
In my activity i use
android:windowSoftInputMode="adjustResize|stateHidden"
and in edittext arguments are:
<EditText
android:id="#+id/et_quantity_test"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:gravity="center_vertical|left"
android:layout_gravity="center_vertical|left"
android:paddingLeft="3dp"
android:imeOptions="actionNext"
android:layout_marginRight="10dp"
></EditText>
The problem : When i click on edittext the keyboard shows but edittext field lost focus and the keyboard type is alphabetic ,not numeric..
Thanks
That is main layout
<?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="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<ImageButton
android:id="#+id/img_back"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:src="#drawable/navigation_back"
android:layout_alignParentRight="true"/>
<TextView
android:id="#+id/tv_title_testing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/test_title"
android:gravity="center_vertical"
android:layout_centerInParent="true"
android:textAppearance="#android:style/TextAppearance.Holo.Medium"
/>
</RelativeLayout>
<Chronometer
android:id="#+id/chronometer_testing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.65"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/test_sub_title"
android:textAppearance="#android:style/TextAppearance.Holo.Medium" />
</LinearLayout>
<!-- <RelativeLayout
android:layout_height="match_parent"
android:layout_width="fill_parent"> -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:id="#+id/lv_product_items_testing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="9"
transcriptMode="alwaysScroll"
android:scrollbars="vertical" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/ll_conf"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_confirm_test_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_gravity="center_horizontal"
android:text="#string/test_conf" />
<Button
android:id="#+id/btn_confirm_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal"
android:text="#string/test_report" />
</LinearLayout>
</LinearLayout>

First write down android:windowSoftInputMode="adjustPan" in Activity in Manifest file to set listview and Edittext and delete android:inputType="numberSigned" from Edittext is help to When you click EditText keyboard open with Alphabetic..

Related

Modifying login Page design to make login button always visible

I have the following layout for login page,i need to reduce the spacing between each element,in short i need to move username,password and login button upwards of the screen ,that is when we open virtual keyboard the login button should be visible always,i tried using 'margintop=-negative value',its not working out.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:andriod="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/loginbackmain"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="top"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="top"
android:background="#drawable/loginformback"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_day"
android:ems="10"
android:hint="username" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="-30dp">
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:drawableLeft="#android:drawable/ic_menu_day"
android:ems="10"
android:hint="password"
android:inputType="textPassword" />
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:onClick="login"
android:text="Login"
andriod:background="#A0522D"/>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="invisible"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Set
android:windowSoftInputMode="stateVisible|adjustPan"
in Android manifest file inside tag

Resize listview according to edittext no of lines

I am stuck in one issue. I took edit text below list view just like chat application. Whenever i press enter key for new line list view does not change its position. I want listview should always display above edittext. Currently edittext displays behind the listview. When i scroll the listview then it displayed above edittext. Please help.
-->
<LinearLayout
android:id="#+id/linearLayout1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="#color/white"
android:paddingBottom="5dp">
<EditText
android:layout_weight="1"
android:id="#+id/chat_msg"
android:layout_height="wrap_content"
android:hint="#string/type_message"
android:paddingLeft="10dp"
android:inputType="textMultiLine"
android:layout_marginRight="5dp"
android:textColor="#color/Black"
android:layout_width="0dip">
<requestFocus></requestFocus>
</EditText>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/send_chat_icon"
android:layout_marginRight="5dp"
android:layout_gravity="bottom"
android:id="#+id/send_msg"></Button>
</LinearLayout>
<RelativeLayout
android:id="#+id/list_layout"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_above="#+id/linearLayout1"
android:background="#drawable/bg">
<FrameLayout
android:id="#+id/sub_fragment_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<LinearLayout
android:id="#+id/heading_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/signuphome_headingbg"
android:gravity="center_horizontal|bottom"
android:orientation="vertical" >
<TextView
android:id="#+id/follower"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/friends"
android:textColor="#color/white"
android:textSize="22sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/add_whisper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:textColor="#color/white"
android:textSize="22sp"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:visibility="gone"
android:text="+" />
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="#+id/follower_list"
android:layout_below="#+id/heading_layout"
android:layout_above="#+id/selected_contacts"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent" />
<ListView
android:id="#+id/follower_listView"
android:layout_below="#+id/heading_layout"
android:layout_above="#+id/selected_contacts"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
android:visibility="gone" />
<Button
android:id="#+id/selected_contacts"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="Done"/>
</RelativeLayout>
here's a pseudo-XML that works for what you want. pretty basic stuff.
<RelativeLayout
<CommentArea align_BottomParent = true;/>
<ListView align_TopParent = true;
align_Above="commentArea"/>
/>

Edittext with Drawable background does not wrap it's contents

I am writing a chat application for learning Android programming in witch I will show the conversations between to users by a list. Any item of conversation list is a set of objects and a EditText with a bubble background. But when I show the conversation the EditText does not wrap it's content and the size of EditText is same in all rows of conversation.
Here is my conversation item's code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/llmain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables" >
<TextView
android:id="#+id/txtTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/chatdate"
android:gravity="center"
android:textAlignment="gravity"
android:textSize="8sp" />
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/llTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/chatme"
android:gravity="top|right"
android:paddingTop="7dp"
android:textAlignment="gravity"
android:visibility="visible" >
<ImageView
android:id="#+id/imgStatusTo"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:scaleType="fitXY"
android:src="#drawable/wait_ic" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.82"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgChatConversationToFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="#drawable/ic_info" />
<TextView
android:id="#+id/txtChatConversationTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="60dp"
android:autoLink="web"
android:background="#color/chatme"
android:drawableBottom="#color/jigari"
android:drawableLeft="#color/jigari"
android:drawableRight="#color/jigari"
android:drawableTop="#color/jigari"
android:gravity="right|top"
android:inputType="none"
android:linksClickable="true"
android:paddingLeft="20dp"
android:paddingRight="40dp"
android:paddingTop="5dp"
android:scrollHorizontally="false"
android:scrollbars="none"
android:selectAllOnFocus="true"
android:singleLine="false"
android:textDirection="rtl" />
</LinearLayout>
<ImageView
android:id="#+id/imgChatConversationTo"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:background="#color/gray"
android:contentDescription="#string/user_image"
android:scaleType="fitXY"
android:src="#drawable/ic_user_image" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/llFrom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/chatyou"
android:paddingTop="7dp"
android:visibility="visible" >
<ImageView
android:id="#+id/imgChatConversationFrom"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#color/gray"
android:contentDescription="#string/user_image"
android:scaleType="fitXY"
android:src="#drawable/ic_user_image" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.82"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgChatConversationFromFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="#drawable/ic_info" />
<TextView
android:id="#+id/txtChatConversationFrom1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginRight="60dp"
android:autoLink="web"
android:background="#color/chatyou"
android:gravity="top|right"
android:inputType="none"
android:linksClickable="true"
android:paddingLeft="45dp"
android:paddingRight="20dp"
android:paddingTop="3dp"
android:scrollHorizontally="false"
android:scrollbars="none"
android:selectAllOnFocus="true"
android:singleLine="false"
android:textAlignment="gravity" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
My problem is on txtConversationFrom and txtConversationTo.
At the code I will hide items that not required there.
How I can force EditText to wrap text and resize to fit text size?
Correct me if I'm wrong but if you're talking about EditText you mean TextView right?
And your problem is that the text displayed in the TextViews won't linebreak if they are too large to fit in?
If yes you should probably add this:
android:inputType="textMultiLine"
to your TextViews.
And probably set the width of your LinearView which contains the txtChatConversationTo TextView to:
android:width="wrap_content"

Focust on ListView item (Android)

I have a problem with my ListView. ListView row contains: TextView field, EditText field and Image field but focused only on EditText field. If I write in Layout attributes android:descendantFocusability="blocksDescendants" then ListView row becomes focusable, but EditText field becomes not focusable. What should I do to get focusable ListView row and EditText field in this row?
Here is the example of my MainActivity layout with ListView and ListView row layout.
MainActivity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="#string/button_select_folder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/button_select_folder"
android:layout_gravity="center_horizontal"
android:layout_marginTop="13dp" >
</Button>
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:visibility="gone"
android:layout_marginTop="10dp"
android:id="#+id/tvPathToPL"
android:text="#string/tvPathToPL"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:id="#+id/btnPathToPL"
android:text="#string/btnPathToPL"
android:visibility="gone"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:visibility="invisible"
android:id="#+id/tlPLName">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvPLName"
android:text="#string/tvPLName"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/etPLName"
android:inputType="textCapWords"
android:hint="#string/etPLName"/>
</TableRow>
</TableLayout>
<Button
android:text="#string/generate_playlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/generate"
android:layout_gravity="center_horizontal"
android:visibility="invisible"
android:layout_weight="0">
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:id="#+id/ExitApp"
android:text="#string/ExitApp"
android:layout_gravity="center_horizontal">
</Button>
</LinearLayout>
ListView row:
<?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="wrap_content"
<!-- android:descendantFocusability="blocksDescendants -->
android:orientation="horizontal">
<LinearLayout
android:id="#+id/LL_Option"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/OptionDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text=""
android:textSize="20sp">
</TextView>
</LinearLayout>
<EditText
android:id="#+id/OptionSongCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="1"
android:clickable="true"
android:textSize="20sp"
android:layout_marginTop="5dp"/>
<ImageView
android:id="#+id/OptionImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher">
</ImageView>
</LinearLayout>
Will be very thankful for help.

Android: Keyboard overlaps with the EditText (with printscreens)

I have an EditText (that the user can type numbers in),
so when the user clicks on the EditText text box a keyboard with numbers is opened.
as you can see the keyboard hides a small part of the text box.
But when I press a key, for example, 0, it looks ok.
Is there anything I can do (besides putting the EditText higher) so it will looks like it does in the second picture?
Edit: the .xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1">
<RelativeLayout android:id="#+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true">
<android.widget.CheckedTextView android:id="#+id/checkedTextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp" android:text="#string/toString"></android.widget.CheckedTextView>
<AutoCompleteTextView android:layout_height="wrap_content" android:id="#+id/autoCompleteTextView1" android:layout_width="fill_parent" android:text="#string/emptyString" android:textSize="17sp" android:gravity="top|left" android:minHeight="62dp">
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/linearLayout2">
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.33333333333" android:text="#string/contactsString" android:textSize="17sp" android:id="#+id/contactsButton"></Button>
<Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="#string/groupsString" android:layout_width="fill_parent" android:id="#+id/groupsButton" android:textSize="17sp"></Button>
<Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="#string/favouritesString" android:layout_width="fill_parent" android:id="#+id/button3" android:textSize="17sp"></Button>
</LinearLayout>
<TextView android:id="#+id/textView1" android:text="#string/messageString" android:layout_height="wrap_content" android:textSize="17sp" android:layout_width="fill_parent"></TextView>
<EditText android:layout_height="wrap_content" android:id="#+id/editText1" android:layout_width="fill_parent" android:gravity="top|left" android:minHeight="105dp"></EditText>
<TextView android:id="#+id/textView2" android:text="#string/repetition" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp"></TextView>
<Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/spinner"></Spinner>
<LinearLayout android:layout_height="wrap_content" android:id="#+id/linearLayout3" android:layout_width="fill_parent">
<ImageView android:src="#drawable/button_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/imageView1" android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/timeET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4"></EditText>
<ImageView android:src="#drawable/button_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/imageView2" android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/dateET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
</LinearLayout>
<RelativeLayout android:id="#+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/linearLayout4" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true">
<Button android:layout_weight="0.5" android:layout_height="wrap_content" android:text="#string/button_ok" android:layout_width="fill_parent" android:id="#+id/button4" android:textSize="17sp"></Button>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="#+id/button5" android:layout_weight="0.5" android:text="#string/button_cancel" android:textSize="17sp"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I have tried your XML and yes you are right the problem occur.
To solve the problem I have written this line in my MainActivity.java hope this help to you,And put the layout XML in ScrollView.
Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
final EditText time = (EditText)findViewById(R.id.timeET);
time.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
final EditText date = (EditText)findViewById(R.id.dateET);
date.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
}
And The XML is Like,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView android:id="#+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:weightSum="1">
---
---
---
</ScrollView>
</LinearLayout>
Change to ScrollView in this way:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" >
<android.widget.CheckedTextView
android:id="#+id/checkedTextView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="17sp"
android:text="#string/toString" />
<AutoCompleteTextView
android:layout_height="wrap_content"
android:id="#+id/autoCompleteTextView1"
android:layout_width="fill_parent"
android:text="#string/emptyString"
android:textSize="17sp"
android:gravity="top|left"
android:minHeight="62dp" >
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2" >
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0.33333333333"
android:text="#string/contactsString"
android:textSize="17sp"
android:id="#+id/contactsButton" />
<Button
android:layout_weight="0.33333333333"
android:layout_height="wrap_content"
android:text="#string/groupsString"
android:layout_width="fill_parent"
android:id="#+id/groupsButton"
android:textSize="17sp" />
<Button
android:layout_weight="0.33333333333"
android:layout_height="wrap_content"
android:text="#string/favouritesString"
android:layout_width="fill_parent"
android:id="#+id/button3"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:text="#string/messageString"
android:layout_height="wrap_content"
android:textSize="17sp"
android:layout_width="fill_parent" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:gravity="top|left"
android:minHeight="105dp" />
<TextView
android:id="#+id/textView2"
android:text="#string/repetition"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="17sp" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner" />
<LinearLayout
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:layout_width="fill_parent" >
<ImageView
android:src="#drawable/button_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:layout_weight="0.1" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/timeET"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_weight="0.4" />
<ImageView
android:src="#drawable/button_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:layout_weight="0.1" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/dateET"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_weight="0.4"
android:layout_marginRight="3dp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true" >
<Button
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:text="#string/button_ok"
android:layout_width="fill_parent"
android:id="#+id/button4"
android:textSize="17sp" />
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/button5"
android:layout_weight="0.5"
android:text="#string/button_cancel"
android:textSize="17sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
put the entire view inside a ScrollView and set the android:windowSoftInputMode = adjustPan it will do the trick.
you just need to add this piece of code,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
Your linear layout here....
</ScrollView>
I have tested it on my HTC Desire and its working fine for me hope it will work for you too.
Set android:windowSoftInputMode on the Activity to "adjustPan":
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.
Beware of one potential bug when using this technique with a fullscreen activity.
You can give some hints to the system on how to handle this via android:windowSoftInputMode element on the declared activity in the AndroidManifest. Try the "adjustResize" value.
android:windowSoftInputMode
This is a much simpler fix than the accepted answer. The key is the <item name="android:windowSoftInputMode">adjustUnspecified</item> line. Add it to your styles.xml:
<style name="AppTheme" parent="#android:Theme.Holo.Light.DarkActionBar">
<item name="android:alertDialogTheme">#style/iconPopUpDialogTheme</item>
</style>
<style name="DialogAppTheme" parent="AppTheme">
<item name="android:dialogTheme">#style/iconPopUpDialogTheme</item>
</style>
<style name="PopUpDialogTheme">
<item name="android:windowSoftInputMode">adjustUnspecified</item>
</style>
try changing linear layout to scroll view...so that if keyboard comes above editt text user can scroll and type...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1">
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:orientation="vertical" android:layout_height="wrap_content"
android:id="#+id/linearLayout1" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<android.widget.CheckedTextView
android:id="#+id/checkedTextView1" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textSize="17sp"></android.widget.CheckedTextView>
<AutoCompleteTextView android:layout_height="wrap_content"
android:id="#+id/autoCompleteTextView1" android:layout_width="fill_parent"
android:textSize="17sp" android:gravity="top|left"
android:minHeight="62dp">
<requestFocus></requestFocus>
</AutoCompleteTextView>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/linearLayout2">
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_weight="0.33333333333"
android:textSize="17sp" android:id="#+id/contactsButton"></Button>
<Button android:layout_weight="0.33333333333"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:id="#+id/groupsButton" android:textSize="17sp"></Button>
<Button android:layout_weight="0.33333333333"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:id="#+id/button3" android:textSize="17sp"></Button>
</LinearLayout>
<TextView android:id="#+id/textView1" android:layout_height="wrap_content"
android:textSize="17sp" android:layout_width="fill_parent"></TextView>
<EditText android:layout_height="wrap_content" android:id="#+id/editText1"
android:layout_width="fill_parent" android:gravity="top|left"
android:minHeight="105dp"></EditText>
<TextView android:id="#+id/textView2" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textSize="17sp"></TextView>
<Spinner android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/spinner"></Spinner>
<LinearLayout android:layout_height="wrap_content"
android:id="#+id/linearLayout3" android:layout_width="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/imageView1"
android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/timeET"
android:inputType="number" android:layout_width="wrap_content"
android:layout_weight="0.4"></EditText>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/imageView2"
android:layout_weight="0.1"></ImageView>
<EditText android:layout_height="wrap_content" android:id="#+id/dateET"
android:inputType="number" android:layout_width="wrap_content"
android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
</LinearLayout>
<RelativeLayout android:id="#+id/relativeLayout2"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/linearLayout4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true">
<Button android:layout_weight="0.5" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/button4"
android:textSize="17sp"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/button5"
android:layout_weight="0.5" android:textSize="17sp"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
please make necesscery changes...i have removed strings and drawable src for my convience..u need to change first
linear layout to scrollview..try without this
android:windowSoftInputMode = adjustPan
Add this simple line in your Manifest.xml file:
android:windowSoftInputMode="adjustResize|stateHidden"

Categories

Resources