Android: EditText NextFocusDown not trigger Spinner - android

In my application I have one registration screen, There are lot of EditTexts and Spinners.
I want to go through the Registrations field one by one.
So I applied android:imeOptions="actionNext" . But It ignores all the Spinners. It will give focus only to EditText. I have also tried setNextFocusDownId(). This is also ignore the spinners.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/reportentry11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/numbers"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="phone"
>
<requestFocus/>
</EditText>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/reportentry12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="#+id/txt_exp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="EXP:"
android:textColor="#000000"
android:textSize="12dp" />
<Spinner
android:id="#+id/spin_date"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
android:focusable="true"
android:focusableInTouchMode="true"
android:nextFocusDown="#+id/spin_year"
android:text="date"
android:textSize="12dp" />
<Spinner
android:id="#+id/spin_year"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="5dp"
android:nextFocusDown="#+id/cvc"
android:text="year"
android:textSize="12dp" />
</LinearLayout>
<EditText
android:id="#+id/cvc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="#string/reg_label_cvc"
android:imeOptions="actionNext"
android:inputType="phone" />
<EditText
android:id="#+id/fname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/reg_label_fname"
android:imeOptions="actionNext" />
<EditText
android:id="#+id/address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/reg_label_address"
android:imeOptions="actionNext" />
<EditText
android:id="#+id/city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/reg_label_city"
android:imeOptions="actionNext"
android:nextFocusDown="#+id/pr_spin" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/reportentry13"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txt_pr"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="PROV:"
android:textColor="#000000"
android:textSize="12dp" />
<Spinner
android:id="#+id/pr_spin"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="date"
android:imeOptions="actionNext"
android:textSize="14dp" />
<EditText
android:id="#+id/pcode"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="#string/reg_label_pcode"
android:imeOptions="actionDone" />
</LinearLayout>
<Button
android:id="#+id/register_register_button"
android:layout_width="wrap_content"
android:background="#drawable/green_button_bg"
android:onClick="completeClicked"
android:text="#string/reg_label_complete"
android:textSize="28dp"
android:textStyle="bold" />
</LinearLayout>
Please provide me the best way to trigger the spinners.

On your edit texts, override onEditorAction and give focus (or do whatever like open your spinner)...
yourEditTXT.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView view, int actionID, KeyEvent event) {
if (actionID == EditorInfo.IME_ACTION_NEXT) {
//do your stuff here...
return true;
}
return false;
}
});
Edit 12/4:
I see you were still struggling with this as of last night, if you didn't find a solution (and didn't post one) or to help others who may read this, this may help to get from spinner to edit text.
mySpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parentview, View v, int position, long id) {
// your spinner proces code
// then when you are done,
yourEditText.setFocusableInTouchMode(true); //if this is not already set
yourEditText.requestFocus(); //to move the cursor
final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); // this line and the one above will open the soft keyboard if it doesn't already open
}
public void onNothingSelected(AdapterView<?> arg0) { }
};

do the following in your xml file:
<Spinnner
android:focusable="true"
android:focusableInTouchMode="true"
android:nextFocusDown="#+id/youedittextid"
/>

Apart from the solutions above to focus on Spinners, here are further troubles with ime options:
If the spinners are between the EditTexts, then the EditTexts that are below the spinners ignore imeOption="actionDone" and lines="1" attributes. In both the cases they accept enter keys and move to next line, when, it should not allow the enter key event.
I found that though the listener for ime was still intact, the ime option set to whatever (next or done), it changed to 0.
So my answer is for second part while I am still trying to make spinners focusable:
xml:
<EditText
android:id="#+id/et_1"
android:layout_width="match_parent"
android:layout_height="#dimen/dp_40"
android:layout_marginLeft="#dimen/dp_8"
android:layout_marginStart="#dimen/dp_8"
android:gravity="start|bottom"
android:hint="#string/et_1"
android:imeOptions="actionNext"
android:inputType="textCapWords" />
<!--This ime option works fine-->
<!--lots of spinners in between these Edit texts-->
<EditText
android:id="#+id/et_2"
android:layout_gravity="start|bottom"
android:layout_marginLeft="#dimen/dp_8"
android:layout_marginStart="#dimen/dp_8"
android:gravity="start|bottom"
android:hint="#string/et_2"
android:imeOptions="actionDone" />
<!--this actionDone is ignored and set to 0-->
[value of actionNext = 5 while that of actionDone = 0, but for edit text et2 reports as 0 in the listener]
set listener:
...
EditText et_1 = view.findViewById(R.id.et_1);
fet_1.setOnEditorActionListener(this);
//==
EditText et_2 = view.findViewById(R.id.et_2);
et_2.setOnEditorActionListener(this);
...
The handling of listeners where the ime actions are ignored too:
#Override
public boolean onEditorAction(TextView textView, int actionID, KeyEvent keyEvent) {
FontEditText et_1 = getView().findViewById(R.id.et_1);
//==
EditText et_2 = getView().findViewById(R.id.et_2);
final int id = textView.getId();
switch (id) {
case R.id.et_1: {
if (actionID == EditorInfo.IME_ACTION_NEXT) {
// works actionID = 5.
//inherited method
activity.hideKeyboard(textView);
fet_bus_entity.clearFocus();
et_business_add.requestFocus();
et_business_add.performClick();
return true;
}
}
break;
case R.id.et_2: {
//following line doesn't work hence commented, value of actionID = 0 here.
// if (actionID == EditorInfo.IME_ACTION_DONE) {
et_business_add.clearFocus();
//inherited method
activity.hideKeyboard(textView);
return true;
// }
}
// break;
}
return false;
}

Related

onFocus function not working properly in Android ?

Hi I am newbie in android, I have 3 edit box and I have set 3 setOnFocusChangeListener based on edit box wise, When I focus mobile no edit box ,I am getting sim no id instead mobile no Id. onFocus function getting called with wrong id's. If I did any any mistake please let us know or else solve the solution.
Source code :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_temp);
objMobileNo = (EditText) findViewById(R.id.mobile_no);
objSimNo = (EditText) findViewById(R.id.sim_no);
objImsiNo = (EditText) findViewById(R.id.imsi_no);
View.OnFocusChangeListener a = new View.OnFocusChangeListener() {
public void onFocusChange(View view, boolean hasFocus) {
if (!hasFocus) {
//this if condition is true when edittext lost focus...
//check here for number is larger than 10 or not
// focusText = "MOBILE";
// Log.d("BKS", "onFocusChange: " + focusText);
Log.d("BKS", "onFocusChange: " + view.getId());
Log.d("BKS", "onFocusChange: " + R.id.mobile_no);
}
}
};
objMobileNo.setOnFocusChangeListener(a);
objSimNo.setOnFocusChangeListener(a);
objImsiNo.setOnFocusChangeListener(a);
XML Code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_marginTop="100dp"
android:id="#+id/mobile_no"
style="#style/Material_Action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_mob_no"
android:inputType="number"
android:maxLength="10" />
<EditText
android:id="#+id/sim_no"
style="#style/Material_Action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_sim_no"
android:inputType="number"
android:maxLength="20" />
<EditText
android:id="#+id/imsi_no"
style="#style/Material_Action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_imsi_no"
android:inputType="number"
android:maxLength="15" />
<EditText
android:id="#+id/status"
style="#style/Material_Action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:visibility="gone" />
<EditText
android:id="#+id/scanning_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:visibility="gone" />
<LinearLayout
android:id="#+id/mLlayoutBottomButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="#+id/verify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_light"
android:text="Verify"
android:textColor="#android:color/white">
</Button>
</LinearLayout>
Thanks in Advance,
Kalanidhi.
You are setting same OnFocusChangeListener for all EditText. so when you focus a new EditText, the current one loses its focus. So for both the events onFocusChange() will be called. But your if condition filters only the view that loses the focus and not the one which got the focus.
So replace
if (!hasFocus) {
}
with this to make it work as expected
if (hasFocus) {
}

Android EditText with icon/button

How can I obtain an EditText as those bellow?
The x button removes the text inserted and the eye button displays the clear password as long as it's pressed. Note that I refer to them as buttons because I don't really know what they actually are nor if they are part of the EditText itself or if they are independent views.
You can just add a button at the right of your EditText
<FrameLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/ScreenLoginContainer">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:hint="#string/enter_password_hint"
android:paddingRight="30dp"
style="#style/ScreenPasswordEditText"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+screen_card_ean_enter/show_password_button"
style="#style/ShowHidePasswordButton"/>
</FrameLayout>
You can use android:drawableRight
Set a Drawable to the right of the text, in EditText, in XML .
android:drawableRight="#drawable/Your_drawable"
You can use this :
android:drawableRight="#drawable/your_icon"
Also for click this answer
may help
This is the prefect way to create an EditText with cross button at the end:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:padding="5dp">
<EditText
android:id="#+id/calc_txt_Prise"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:layout_marginTop="20dp"
android:textSize="25dp"
android:textColor="#color/gray"
android:textStyle="bold"
android:hint="#string/calc_txt_Prise"
android:singleLine="true" />
<Button
android:id="#+id/calc_clear_txt_Prise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="right|center_vertical"
android:background="#drawable/delete" />
And now to clear the EditText upon click you can use
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditTextID.setText("");
}
});
And in order to make the password visible till the button is pressed, you can implement it this way:
yourButton.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch ( event.getAction() ) {
case MotionEvent.ACTION_DOWN:
editText.setInputType(InputType.TYPE_CLASS_TEXT);
break;
case MotionEvent.ACTION_UP:
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
break;
}
return true;
}
});
The design support library has a setPasswordVisibilityToggleEnabled method: https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setPasswordVisibilityToggleEnabled(boolean)
This would be good for your password edittext, but not the username one.

Move to next Edit text

i have customEditText
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/five_margin"
android:focusableInTouchMode="true"
android:orientation="horizontal"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout"
>
<EditText
android:id="#+id/edt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="#dimen/sub_heading"
android:textColorHint="#color/hind_text_col0r"
android:inputType="textCapSentences|textAutoCorrect|textMultiLine"
android:textColor="#color/active_text_col0r"
/>
</android.support.design.widget.TextInputLayout>
and using it As follow
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.paisa.main.base.ui.widget.CustomEditText
android:id="#+id/custom_edt_investor_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
/>
<com.paisa.main.base.ui.widget.CustomEditText
android:id="#+id/custom_edt_nominee_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
how can i move investor name to nominee name edit text via soft input keyboard
i had use imeoption next bt it didn't work its hide the keyboard.
This will helps you :- make this for all TextView ...
custom_edt_investor_name.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
custom_edt_investor_name.clearFocus();
custom_edt_nominee_name.requestFocus();
return true;
}
return false;
}
});
Use the android:nextFocusDown param to specify which field you'd like to get focus when the user hits the enter key.
Example :
android:inputType="text"
android:nextFocusDown="#+id/..."

EditText value is reversed

I've got an odd one. I'm trying to format some text while the user types into an EditText field. I am using the TextWatcher and responding to afterTextChanged event (code below). What is odd is after the first time this logic runs the text starts to become reversed. It seems that the Editable object contains the string backwards. Does anyone have any idea how to fix this?
_textWatcher = new TextWatcher()
{
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3)
{
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3)
{
}
#Override
public void afterTextChanged(Editable editable)
{
Editable e = textView.getText();
String text = e.toString();
logger.d("[FormListAdapter][addTextChangedListener] Format Text: " + text);
Number numVal = FormFieldBusiness.ConvertStringToNumber(text, formField.GetFormFieldType());
String fText = FormFieldBusiness.GetFormattedValue(numVal, formField.GetFormFieldType());
editText.removeTextChangedListener(_textWatcher);
textView.setText(text);
editText.addTextChangedListener(_textWatcher);
}
};
editText.addTextChangedListener(_textWatcher);
* UPDATE *
In an attempt to help anyone out there who's looking at this here is my XML layout file.
As I mentioned before the text is correct until after the first the time setText method is called. After that the Editable object is reversed.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="120dp">
<!-- Top Layout -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:weightSum="10"
android:id="#+id/TopLayout">
<TextView
android:id="#+id/TitleTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7"
android:gravity="center_vertical"
android:text="Headling Rent (pa)"
android:textSize="16dp"
style="#style/KelFormListItemLabel" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:weightSum="2"
android:background="#color/formListItemValueBackgroundColor">
<ImageView
android:id="#+id/CurrencyIconView"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_weight="0"
android:src="#drawable/icon_currency_pound"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp" />
<EditText
android:id="#+id/ValueTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="right|center_vertical"
android:text="20,000"
android:textSize="16dp"
android:inputType="number"
android:selectAllOnFocus="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textIsSelectable="true"
style="#style/KelFormListItemValue"/>
</LinearLayout>
</LinearLayout>
<!-- Bottom Layout -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:weightSum="10"
android:id="#+id/BottomLayout"
android:layout_below="#+id/TopLayout">
<TextView
android:id="#+id/BottomTitleTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7"
android:gravity="center_vertical"
android:text="Headling Rent (pa)"
android:textSize="16dp"
style="#style/KelFormListItemLabel" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:weightSum="2"
android:background="#color/formListItemValueBackgroundColor">
<ImageView
android:id="#+id/BottomCurrencyIconView"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_weight="0"
android:src="#drawable/icon_currency_pound"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp" />
<EditText
android:id="#+id/BottomValueTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="right|center_vertical"
android:text="20,000"
android:textSize="16dp"
android:inputType="number"
android:selectAllOnFocus="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textIsSelectable="true"
style="#style/KelFormListItemValue"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
The issue is you are setting the text in the EditText field (even though you have removed the listener) you are listening for. this is causing the cursor to move to the beginning of the line, therefore making it type backwards
try changing from a TextWatcher to TextView.OnEditorActionListener and listen for the action key set on the EditText so when they hit the action key, it does your desired functionality.
add
android:imeOptions="actionDone"
to your button xml and assign it with
TextView.OnEditorActionListener editingActionListener = new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) || actionId == EditorInfo.IME_ACTION_DONE) {
//do stuff where you set the text here
}
return true;
}
};
editText.setOnEditorActionListener(editingActionListener);
alternatively, you can use OnFocusChangeListener
View.OnFocusChangeListener focusChangeListener = new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (v.getClass().equals(EditText.class)) {
if (!hasFocus) {
//do your stuff here
}
}
}
};
editText.setOnFocusChangeListener(focusChangeListener);
Simply move the cursor to the correct position in your TextWatcher after setting the EditText content:
#Override
public void afterTextChanged(Editable editable)
{
...
int position = editText.getSelectionStart();
editText.setText(text);
editText.setSelection(position);
...
}

How to make button come down after edit text field?

I have a piece of code which shows a static text, an edit text as a search box and a submit button to submit the query .
The code kind of looks like this :
public class MyActivity extends Activity {
TextView textView;
private EditText edittext;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mine);
textView = (TextView) findViewById(R.id.textView1);
textView.setText("Enter your search String :");
addKeyListener();
addListenerOnButton();
}
//Implement the method
public void addKeyListener() {
// get edit text component
edittext = (EditText) findViewById(R.id.searchText);
// add a key listener to keep track user input
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// if key down and "enter" is pressed
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// display a floating message
Toast.makeText(RecipeActivity.this,
edittext.getText(), Toast.LENGTH_LONG).show();
return true;
} else if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_9)) {
// display a floating message
Toast.makeText(RecipeActivity.this,
"Aboriginal text!", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
}
//Implement the button
public void addListenerOnButton() {
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
/* I will capture the search string here */
}
});
}
}
The activity screen comes up like this :
EDIT : The XML layout:
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".RecipeActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:label="#string/search_label"
android:hint="#string/search_hint" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</RelativeLayout>
As you can see the submit button is overlapping the edit text search box. How can i make the button element come down ?
It would be better to use LinearLayout with android:orientation="vertical" in your xml Layout because it's much cheaper than RelativeLayout to render.
Solution with LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
If you have to use RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/searchText"
android:text="Submit" />
</RelativeLayout>
See RelativeLayout Documentation for further Informations.
Use android:layout_alignParentBottom="true" in your
add android:below reference
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:below="#+id/searchText"
android:text="Submit" />

Categories

Resources