Moving cursor to the next field - android

How do I move the cursor to the next line? I have two spinners, then a title edit text box and then two edit text boxes in which I am setting the date using a date picker. When setting the date in the "To"-field, the cursor is moved back to the Title field. After selecting the date I want it move to the next field which is "Send By", but it keeps returning to the previous field which is title field. Can anybody help?

android:nextFocusDown="#+id/.."
android:nextFocusLeft="#+id/.."
android:nextFocusRight="#+id/.."
android:nextFocusUp="#+id/.."
or
Spinner spinner=(Spinner)findViewById(R.id.SpinnerGender);
spinner.setFocusable(true);
spinner.setFocusableInTouchMode(true);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if(flag == false)
flag = true;
else
edtTitle.requestFocus();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});

You can try to call requestFocus() on the corresponding EditText in the DatePicker.OnDateChangedListener method.

Kindly add this line to xml file Spinner/EditText Control..
android:imeOptions="actionNext"
or
android:imeOptions="actionNext"
android:singleLine="true"
Hope, this might help you..

Related

change color of button when list item is selected

i'm working on a listview in an activity and i want when ever i longpressed any listitem the Button on the action bar changes its color like as get highlihted as suppose " i select
list item the button on the action bar changes from white to gray" .
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// changes the color button ;
return false;
}
});
or is there any other way that i can do this.
I dont have enough reputation to post a pictures Firstly it looks like Before selecting any item and its looks like thisWhen item is long pressed or selected hope you understand my probleum ,
Thanks in advance
Edit: as misunderstood original question:
int mPosition = -1;
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
if(mPosition!=-1) {
//reset color of previously pressed item to white
lv.getChildAt(mPosition).setBackgroundColor(Color.WHITE);
}
//set current item to fray.
lv.getChildAt(pos).setBackgroundColor(Color.GRAY);
//put value of currently selected item to mPosition.
mPosition = pos;
return true;
}
});
Old answer below:
Add this into your method.
Button button1 = (Button)findViewById(R.id.button1);
if(this condition){
button1.setBackgroundColor(Color.GRAY);
}else{
//whatever..
}
This answer covers the same principle, but in more detail using the resources.
you can give color to list item when selected with
android:listSelector="#color/AnyColor" in .xml file .. see coding
<ListView
android:id="#+id/nameOfYourListview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:background="AnyYouWant"
<!--code for color the selected item --> android:listSelector="ColorHereWhichYouWant" >
</ListView>

Switch to the next field when autocompleted

I have got a lot of AutoCompleteTextViews and EditText in my app, and i wanted to make user input a bit more easy :
I would like to go to the next field when the user hit the dropdown list.
Thank you if you have any infos about how to do that !
Here is what i finally did and which worked :
AutoCompleteField.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
TextView nextField = (TextView)AutoCOmpleteField.focusSearch(View.FOCUS_FORWARD);
nextField.requestFocus();
}
});
hey add this to your edittext xml
android:imeOptions="actionNext"
and add
android:imeOptions="actionDone"
in your last edit text to finish

keyboard bug with onClickListener in EditText

I have a problem with an editText. I want to put a default text in this editText and when you click on the text disappear and you can wirte a number. Every thing is going well with that code for the layout:
<EditText
android:id="#+id/yearEdit"
android:layout_width="145dp"
android:layout_height="45dp"
android:layout_marginBottom="40dp"
android:gravity="center"
android:ems="10"
android:inputType="number|numberDecimal"
android:text="#string/chooseDate"
android:textSize="13sp"
/>
and in the activity the edit text have as textWatcher and onClickListener :
private class ChooseYear implements TextWatcher, OnClickListener {
#Override
public void afterTextChanged(Editable arg0) {
if (!yearEdit.getText().toString().equals("")) {
yearChoose = Integer.parseInt(yearEdit.getText()
.toString());
}
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
#Override
public void onTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
#Override
public void onClick(View arg0) {
if (yearChoose == -1) {
yearEdit.setText("");
}
}
}
But my problem is : When i had it as the onClickListener, the android keyboard doesn't close anymore when i click on its "Done" button. Does someone know why ? Does it exist a proper way to fix it ?
Thanks a lot for your help,
Eliott
For people who are interest, this is my conclusion on my own problem.
It looks like the keyBoard doesn't work proprely (The "Done" button is not closing the keyboard) when you add an OnClickListener on the EditText. To solve the problem I have to add the line :
yearEdit.setOnClickListener(null);
in the code. When the OnClickListener is set to null, The "Done" button restart to work normally. You have to re-set the OnClickListener if you need it again after (not my case).
My opinion is that could be an Android bug, because there is no logic than an OnClickListener have an effect on the keyboard. If you want to share your opinion about it, i will be interest.

edittext focused on visible in android

I have one edittext.It is INVISIBLE by defalut.On click of list item it is visible.I want to focust edit text when it is visible.and opens soft keyboard.i have searches alot but it is no working on visible and Invisible.
CODE:
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
list_selection=((TextView)arg1).getText().toString();
if(list_selection.equals("Other"))
{
edit_other.setVisibility(View.VISIBLE);
edit_other.setFocusable(true);
edit_other.setCursorVisible(true);
other.setVisibility(View.VISIBLE);
image.setVisibility(View.VISIBLE);
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
try to use
edit_other.requestFocus();
You could give this a try and see :
if(edit_other.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
Hope it helps !

Android Spinner to give text answer displayed

I currently have a spinner giving the same result as the spinner selection. For example if I selected the word "Blue" from the spinner drop down the word "Blue" would be displayed in a text box below the spinner.
How would I go about displaying a different text result than the spinner selection name. For example, if I select "Blue" from the spinner I get a different paragraph of text shown below in the text box, which corresponds to my selection?
Any help would be appreciated as I am new to this.
You need to set a listener on your spinner. Here is an example:
mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String s = (String) mySpinner.getSelectedItem();
if (s.equals("Blue")){
myTextView.setText("GIANT PARAGRAPH");
}//else ifs and so on...
}
public void onNothingSelected(AdapterView<?> arg0) {}
});
Well all you need to do is set a conditional statement. Right now you're saying if blue is selected set the text for (yourtextviewname) to "blue". All you have to do is instead say, if blue is selected set the text to "whatever you want". Here is an example. This is not exact code, just an example of what you might want to try.
if (spinner.equals("blue")) {
TextView tv = (TextView) findViewById(R.id.textview1);
tv.setText("Whatever I want to type!");
}
You can also set the TextView by a String resource. the only difference is you would put
tv.setText(R.string.something);

Categories

Resources