New for android and programming in general, so I learn concepts when I go.
I have a LinearLayout to which I add edittexts dynamically.
I need to get the index and id of any edittext when it is selected or in focus.
I tried to scroll the counter to check for the selected one like this:
int count = llmain.getChildCount();
for (int i=0; i< count; ++i) {
if ((llmain.getChildAt(i).isSelected()) == true){
}
but I have no idea if it is even close, and it will only be for the index .....
Help will be greatly appreciated!
thank
EDIT: There is still no reliable way to achieve this. Example below with
if(v instanceOf EditText) {
id = v.getId();
index = ll.indexOfChild(v);
-1 , . ", " if ", , . , " instanceof" ,
if (v != null){
id = v.getId();
index = llmain.indexOfChild(v);
setFocusableInTouchMode (true), , , clearFocus(), EditTexts . , , EditTexts .
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&(event.getKeyCode() == 66))
{
View myView = linflater.inflate(R.layout.action, null);
myView.setId(pos);
pos++;
myView.setFocusableInTouchMode(true);
llmain.addView(myView);
myView.requestFocus();
View v = llmain.findFocus();
if (v != null){
id = v.getId();
index = llmain.indexOfChild(v);
Context context = getApplicationContext();
CharSequence text = "index is:" + index + "id is:" + id;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
return false;
}
, setFocusableInTouchMode, -1 ID. ? ( ) , .....
, ? !