I have 4 EditText
's now I want to put text in it on the one that is focussed and after that I want to go to the next EditText
anyone an idea how I can do this?
what I want:
focussedEditText.setText("hi");
focusOnNextEditText;
I have 4 EditText
's now I want to put text in it on the one that is focussed and after that I want to go to the next EditText
anyone an idea how I can do this?
what I want:
focussedEditText.setText("hi");
focusOnNextEditText;
edit_Text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
edit_Text.setText("Your text");
Second_edit_text.requestFocus();
}else {
}});
I think this is what you want..
EditText e1,e2;
Button b1,b2;
String evalue;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
e1=(EditText)findViewById(R.id.editText1);
e2=(EditText)findViewById(R.id.editText2);
b1=(Button)findViewById(R.id.button1);
b2=(Button)findViewById(R.id.button2);
e1.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent arg1)
{
evalue="1";
return false;
}
});
e2.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent arg1)
{
evalue="2";
return false;
}
});
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
if(evalue=="1")
{
e1.setText("yes");
}
if(evalue=="2")
{
e2.setText("yes");
}
}
});
b2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
if(evalue=="1")
{
e1.setText("No");
}
if(evalue=="2")
{
e2.setText("No");
}
}
});
}
Am I correct... If yes then please refer this answer for more detail..
you have 4 edittext.. which implies that they are views in a viewgroup (Viewgroup is the parent view- or a view that has children- could be linear or realative or frame even viewflipper layout)? so to this
Viewgroup.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
Viewgroup.getFocusedChild().setText("Ellt's solution works");
return false;
}
});
correct silly errors
EDIT 1: well all you have to do is override it-(but this will only be called once for a viewgroup), it when it gets focus.. but after that it doesnt loose it..
you can always implement it your way, i dont really know how your code is constructed but you can always get the focused child by Viewgroup.getFocusedChild()
and you can also do this
private void customfocuses(View v){ // the view here can be replaced with EditText directly- but for wider range i used View
v.setText("Ellt's solution works");
Viewgroup.focusSearch(v,View.FOCUS_DOWN);
v.clearFocus(); // remove if you want..just wanted to follow code structure..
customfocuses(Viewgroup.getFocusedChild());
}
all this does is it sets the text to the view and also, tells the viewgroup to find a next
view that wants focus and gives it to it and the whole scenario begins again with
customfocuses(Viewgroup.getFocusedChild());
also the View.FOCUS_DOWN
specifies the
direction of the searching for focus views..
So, then you call this the first time you need it.. customfocuses(Viewgroup.getFocusedChild());
what the clearFocus()
does is it removes focus from a view.. thats about it
Note: the Viewgroup in ma code are to be replaced with actually viewgroup not the class as i did..
let me know if i it ws good..okay, Sir? lol..