How to make button come down after edit text field? - android

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" />

Related

SlidingDrawer underlap in RelativeLayout

I used a SlidingDrawer like in this tutorial
It works in a LinearLayout, but there is always a whitespace depending of the hight of the slider and all other stuff show up below the whitespace.
The soloution should be to use a Relative Layout. This deletes the whitespace but the handlerbutton from the slider seems to be under the content in the scrollview and don't do anything by clicking on it. See the screenshot
MainActivity.xml
<RelativeLayout 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="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tbar"
layout="#layout/primerdivisor" />
<SlidingDrawer
android:id="#+id/SlidingDrawer"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:content="#+id/contentLayout"
android:handle="#+id/slideButton"
android:orientation="vertical"
android:padding="10dip"
android:rotation="180">
<!-- Handle button -->
<Button
android:id="#+id/slideButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_selector"
android:ems="10"
android:rotation="180"
android:text="Show" android:clickable="true"/>
<!-- Content Layout -->
<LinearLayout
android:id="#+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFCC"
android:gravity="center"
android:orientation="vertical"
android:padding="10dip">
<Button
android:id="#+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#drawable/button_selector"
android:text="Button 1"
android:textColor="#color/textBlack" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#drawable/button_selector"
android:gravity="center"
android:padding="5dp"
android:text="Text View Item"
android:textColor="#color/textBlack" />
</LinearLayout>
</SlidingDrawer>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical">
....
MainActivity.java
...
private void createSlider(){
slideButton = (Button) findViewById(R.id.slideButton);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
b1 = (Button) findViewById(R.id.Button01);
textView = (TextView) findViewById(R.id.text);
// Setting Listeners to all buttons and textview
setListeners();
// Listeners for sliding drawer
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
// Change button text when slider is open
Log.i("----","blaaaaaa open");
slideButton.setText("Close");
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
// Change button text when slider is close
slideButton.setText("Open");
}
});
}
// Listeners method
void setListeners() {
b1.setOnClickListener(this);
textView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// Toast shown on sliding drawer items click
if (v.getId() == R.id.text) {
Toast.makeText(MainActivity.this, textView.getText() + " Clicked",
Toast.LENGTH_SHORT).show();
} else {
Button b = (Button) v;
Toast.makeText(MainActivity.this, b.getText() + " Clicked",
Toast.LENGTH_SHORT).show();
}
}
...
The slider should overlap the scrollview when its whiped out
In view hierarchy terms, views defined at the beginning of your layout XML are "deeper" than those defined later.
In your case your ScrollView is added to the hierarchy after your SlidingDrawer so what your seeing is to be expected.
Move your SlidingDrawer to below your ScrollView and it should be above it.

Custom Keyboard is hiding the Edit box in Android

I have designed a custom key board with only numeric keys. I have followed the below link:
example
Now when i am touching the edit box, key board is appearing. But if i have 10 editboxes, and i am touching the 10th edit box, key board is appeared and hiding the edit box.How can i make the edit box will scroll up automatically so that it will be not hidden.
I have written the below layout code for xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/edittext0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext0"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext1"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext2"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext3"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:inputType="text" />
</RelativeLayout>
</ScrollView>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
Also here is my custom keyboard java class:
class CustomKeyboard {
/** A link to the KeyboardView that is used to render this CustomKeyboard. */
private KeyboardView mKeyboardView;
/** A link to the activity that hosts the {#link #mKeyboardView}. */
private Activity mHostActivity;
/** The key (code) handler. */
private OnKeyboardActionListener mOnKeyboardActionListener = new OnKeyboardActionListener() {
public final static int CodeDelete = -5; // Keyboard.KEYCODE_DELETE
public final static int CodePrev = 55000;
public final static int CodeNext = 55001;
public final static int CodeDone = 55002;
#Override
public void onKey(int primaryCode, int[] keyCodes) {
// NOTE We can say '<Key android:codes="49,50" ... >' in the xml
// file; all codes come in keyCodes, the first in this list in
// primaryCode
// Get the EditText and its Editable
View focusCurrent = mHostActivity.getWindow().getCurrentFocus();
if (focusCurrent == null
|| focusCurrent.getClass() != EditText.class)
return;
EditText edittext = (EditText) focusCurrent;
Editable editable = edittext.getText();
int start = edittext.getSelectionStart();
// Apply the key to the edittext
if (primaryCode == CodeDone) {
hideCustomKeyboard();
}
else if (primaryCode == CodeDelete)
{
if (editable != null && start > 0)
editable.delete(start - 1, start);
}
else if (primaryCode == CodePrev) {
View focusNew = edittext.focusSearch(View.FOCUS_BACKWARD);
if (focusNew != null)
focusNew.requestFocus();
}
else if (primaryCode == CodeNext) {
View focusNew = edittext.focusSearch(View.FOCUS_FORWARD);
if (focusNew != null)
focusNew.requestFocus();
}
else { // insert character
editable.insert(start, Character.toString((char) primaryCode));
}
}
#Override
public void onPress(int arg0) {
}
#Override
public void onRelease(int primaryCode) {
}
#Override
public void onText(CharSequence text) {
}
#Override
public void swipeDown() {
}
#Override
public void swipeLeft() {
}
#Override
public void swipeRight() {
}
#Override
public void swipeUp() {
}
};
/**
* Create a custom keyboard, that uses the KeyboardView (with resource id
* <var>viewid</var>) of the <var>host</var> activity, and load the keyboard
* layout from xml file <var>layoutid</var> (see {#link Keyboard} for
* description). Note that the <var>host</var> activity must have a
* <var>KeyboardView</var> in its layout (typically aligned with the bottom
* of the activity). Note that the keyboard layout xml file may include key
* codes for navigation; see the constants in this class for their values.
* Note that to enable EditText's to use this custom keyboard, call the
* {#link #registerEditText(int)}.
*
* #param host
* The hosting activity.
* #param viewid
* The id of the KeyboardView.
* #param layoutid
* The id of the xml file containing the keyboard layout.
*/
public CustomKeyboard(Activity host, int viewid, int layoutid) {
mHostActivity = host;
mKeyboardView = (KeyboardView) mHostActivity.findViewById(viewid);
mKeyboardView.setKeyboard(new Keyboard(mHostActivity, layoutid));
mKeyboardView.setPreviewEnabled(false); // NOTE Do not show the preview
// balloons
mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
// Hide the standard keyboard initially
mHostActivity.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
/** Returns whether the CustomKeyboard is visible. */
public boolean isCustomKeyboardVisible() {
return mKeyboardView.getVisibility() == View.VISIBLE;
}
/**
* Make the CustomKeyboard visible, and hide the system keyboard for view v.
*/
public void showCustomKeyboard(View v) {
mKeyboardView.setVisibility(View.VISIBLE);
mKeyboardView.setEnabled(true);
if (v != null)
((InputMethodManager) mHostActivity
.getSystemService(Activity.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
/** Make the CustomKeyboard invisible. */
public void hideCustomKeyboard() {
mKeyboardView.setVisibility(View.GONE);
mKeyboardView.setEnabled(false);
}
/**
* Register <var>EditText<var> with resource id <var>resid</var> (on the
* hosting activity) for using this custom keyboard.
*
* #param resid
* The resource id of the EditText that registers to the custom
* keyboard.
*/
public void registerEditText(int resid) {
// Find the EditText 'resid'
EditText edittext = (EditText) mHostActivity.findViewById(resid);
// Make the custom keyboard appear
edittext.setOnFocusChangeListener(new OnFocusChangeListener() {
// NOTE By setting the on focus listener, we can show the custom
// keyboard when the edit box gets focus, but also hide it when the
// edit box loses focus
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
showCustomKeyboard(v);
else
hideCustomKeyboard();
}
});
edittext.setOnClickListener(new OnClickListener() {
// NOTE By setting the on click listener, we can show the custom
// keyboard again, by tapping on an edit box that already had focus
// (but that had the keyboard hidden).
#Override
public void onClick(View v) {
showCustomKeyboard(v);
}
});
// Disable standard keyboard hard way
// NOTE There is also an easy way:
// 'edittext.setInputType(InputType.TYPE_NULL)' (but you will not have a
// cursor, and no 'edittext.setCursorVisible(true)' doesn't work )
edittext.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
EditText edittext = (EditText) v;
int inType = edittext.getInputType(); // Backup the input type
edittext.setInputType(InputType.TYPE_NULL); // Disable standard
// keyboard
edittext.onTouchEvent(event); // Call native handler
edittext.setInputType(inType); // Restore input type
return true; // Consume touch event
}
});
// Disable spell check (hex strings look like words to Android)
edittext.setInputType(edittext.getInputType()
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
}
Help me please!!
Thanks,
Arindam
I had the exact same problem and after a full days research i have finally solved it.
Here is how:
I have nearly identical xml layout as yours but i have multiple KeyboardViews because i need different keyboards for different EditTexts.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="HardcodedText,TextFields" >
<ScrollView
android:id="#+id/scroll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:paddingBottom="16dp">
<TextView
android:id="#+id/DecLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Decimal" />
<EditText
android:id="#+id/DecText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true" />
<TextView
android:id="#+id/HexLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Hexadecimal" />
<EditText
android:id="#+id/HexText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true" />
<TextView
android:id="#+id/BinaryLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Binary" />
<EditText
android:id="#+id/BinaryText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true" />
<TextView
android:id="#+id/OctalLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Octal" />
<EditText
android:id="#+id/OctalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_gravity="fill" />
</LinearLayout>
</ScrollView>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview_hex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyBackground="#drawable/btn_keyboard_key_ics"
android:visibility="gone" />
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview_dec"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyBackground="#drawable/btn_keyboard_key_ics"
android:visibility="gone" />
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview_oct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyBackground="#drawable/btn_keyboard_key_ics"
android:visibility="gone" />
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview_bin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyBackground="#drawable/btn_keyboard_key_ics"
android:visibility="gone" />
It is not enough. I also needed to set ScrollView's android:layout_above property when the KeyboardView is shown and i did this with an interface:
public interface OnKeyboardStateChangedListener
{
public void OnDisplay(View currentview, KeyboardView currentKeyboard);
public void OnHide(KeyboardView currentKeyboard);
}
And implemented this interface to my MainActivity to edit ScrollView's properties:
public class MainActivity extends Activity BaseKeyboard.OnKeyboardStateChangedListener
Also i passed MainActivity as a parameter and saved as OnKeyboardStateChangedListener:
private OnKeyboardStateChangedListener mStateListener;
public BaseKeyboard(Activity host, int viewid, int layoutid, OnKeyboardStateChangedListener listener) {
..
..
mStateListener = listener;
}
And invoked it when displaying/hiding the keyboard:
public void showCustomKeyboard( View v ) {
mKeyboardView.setVisibility(View.VISIBLE);
mKeyboardView.setEnabled(true);
if( v!=null ) {
mStateListener.OnDisplay(v, mKeyboardView);
((InputMethodManager)mHostActivity.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
public void hideCustomKeyboard() {
mKeyboardView.setVisibility(View.GONE);
mKeyboardView.setEnabled(false);
mStateListener.OnHide(mKeyboardView);
}
And finally i edited the parameters in the MainActivity:
#Override
public void OnDisplay(View currentview, KeyboardView currentKeyboard) {
ScrollView mScroll = (ScrollView) findViewById(R.id.scroll_content);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ABOVE, currentKeyboard.getId());
mScroll.setLayoutParams(params);
mScroll.scrollTo(0, currentview.getBaseline()); //Scrolls to focused EditText
}
#Override
public void OnHide(KeyboardView currentKeyboard) {
ScrollView mScroll = (ScrollView) findViewById(R.id.scroll_content);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
mScroll.setLayoutParams(params);
}
Here are the screenshots:
How it should look without keyboard
With a keyboard displayed
Notes:
I have LinearLayout instead of RelativeLayout inside ScrollView because when my keyboard is shown, ScrollView works as needed but it cuts the most bottom View in half and padding or margin doesn't work with RelativeLayout in this situation but adding a paddingBottom to LinearLayout pushes it back and all of the View is visible. I couldn't find another way to fix this.
You should try different size of paddings to satisfy your needs.
I can provide full source code and additional info if you need.
Did check it and working fine.
Your main layout is a RelativeLayout which gives whole a relative layout and so everything gets change relatively in view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/edittext0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext0"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext1"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext2"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:inputType="text" />
<EditText
android:id="#+id/edittext4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edittext3"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:inputType="text" />
</RelativeLayout>
</ScrollView>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
Check this output I just tried
Img1 = http://i44.tinypic.com/2412r0n.png
Img2 = enter link description here

How to set EditText values to the RangeSeekbar when edittext values based moving the rangeseekbar?

I am facing one issue while using customRangeSeekBar in android when rangeseekbar movies based on Edittext values my RangeSeekbar values Startingvalue startingvalue 0 and endingvalue 30
My requirement is suppose i will take two edittexts
firstedittext value is 10 and second edittextvalue is 20 based on this values RangeSeekbar will move
I wrote xml like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" >
<!-- <RelativeLayout
android:id="#+id/relative1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<WebView
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout> -->
<RelativeLayout
android:id="#+id/relative2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relative1"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentLeft="true"
>
<TextView
android:id="#+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:text="Start"
android:paddingBottom="5dp"
android:textColor="#0072ff"
android:textStyle="bold" />
<EditText
android:id="#+id/edt_starttime"
android:layout_width="50dp"
android:layout_height="30dp"
android:background="#0072ff"
android:inputType="number"
android:imeOptions="actionDone"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true"
>
<TextView
android:id="#+id/end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingBottom="5dp"
android:text="End"
android:textColor="#0072ff"
android:textStyle="bold"/>
<EditText
android:id="#+id/edt_endtime"
android:layout_width="50dp"
android:layout_height="30dp"
android:background="#0072ff"
android:inputType="number"
android:imeOptions="actionDone"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relative2"
android:orientation="horizontal"
android:layout_margin="10dp"
android:id="#+id/layout">
</LinearLayout>
</RelativeLayout>
I used custom RangeSeekbar class like
RangeSeekBar.java
this class is developed based on this link
and finally my activity class is
MainActivity2.java
public class MainActivity2 extends Activity
{
//declaring widgets and variables...............
WebView webView1;
TextView start,end;
EditText edt_starttime,edt_endtime;
String url,edt_starttime1;
View handler1;
int minValue1;
#Override
//onCreate() starts............
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//getting refrences of widgets.......
webView1=(WebView)findViewById(R.id.webView1);
start=(TextView)findViewById(R.id.start);
end=(TextView)findViewById(R.id.end);
edt_starttime=(EditText)findViewById(R.id.edt_starttime);
edt_endtime=(EditText)findViewById(R.id.edt_endtime);
edt_starttime = (EditText) findViewById(R.id.edt_starttime);
// edittext listenr starts...........
// editettxt start listener ends.........
//editetxt end listener starts..............
edt_endtime.setOnEditorActionListener(new OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
// TODO Auto-generated method stub
if (actionId == EditorInfo.IME_ACTION_DONE)
{
Log.e("Ram san","jhgkfdjgh");
String edt_endtime1=edt_endtime.getText().toString();
if(edt_endtime1.length()!=0)
{
minValue1=Integer.parseInt(edt_endtime1);
Log.e("", ""+minValue1);
}
return true; // consume.
}
// pass on to other listeners.
return false;
}
});
//edittext listeners ends.................
// create RangeSeekBar as Integer range between 20 and 75
RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(0, 30, MainActivity2.this);
seekBar.setLeft(25);
seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>()
{
#Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, final Integer minValue, Integer maxValue)
{
edt_starttime.setText(""+minValue);
edt_endtime.setText(""+maxValue);
Log.e("values ", ""+ minValue + ", MAX=" + maxValue);
}
});
// add RangeSeekBar to pre-defined layout
ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
// layout.setP
layout.addView(seekBar);
}
//onCreate() ends.................
}
How can I set EditText values to the RangeSeekbar when edittext values are based on moving the rangeseekbar?

How to setting listener for button inside the Crouton Toast and clear that Crouton Toast using that button?

I have an app, which shows toast below the actionbar. I'm using Crouton library for displaying toast. Here I'm placing custom layout for toast, that layout contains one textview and one button (for close option). So Toast appears with button. If I click that it should close the toast but nothing happens.. Below Code for this example. Any Help Appreciated
MainActivity.java
public class MainActivity extends SherlockActivity implements OnClickListener {
private View customToastView;
private TextView customToastMessageView;
private Button customToastCloseButton;
private Button doneButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
doneButton = (Button) findViewById(R.id.done_button);
customToastView = getLayoutInflater().inflate(R.layout.toast_custom_layout, null);
customToastMessageView = (TextView) customToastView.findViewById(R.id.messages);
customToastCloseButton = (Button) customToastView.findViewById(R.id.close_button);
customToastCloseButton.setOnClickListener(this);
doneButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.done_button:
Crouton.cancelAllCroutons();
customToastMessageView.setText("Message");
Crouton.show(this, customToastView);
break;
case R.id.close_button:
Crouton.cancelAllCroutons();
break;
}
}
}
toast_custom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="23dp"
android:text="Button" />
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/done_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="146dp"
android:text="Button" />
</RelativeLayout>

Android: EditText NextFocusDown not trigger Spinner

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;
}

Categories

Resources