Jump to content

Recommended Posts

Posted

Bom dia,

Alguém sabe como faço para percorrer todas as caixas de texto de um formulário em android ?

A minha intenção é percorrer o formulário e saber quais caixas contêm texto.

Obrigado.

Estranha forma de vida que tem a capacidade de transformar comandos em mensagens de erro.

ndsotware.org

Posted

http://developer.android.com/reference/android/view/ViewGroup.html

Tens o getChildAt(int index) e o getChildCount(). Tens é que verificar se o elemento é, de facto, uma caixa de texto.

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Posted
LinearLayout formLL = (LinearLayout) findViewById(R.id.formll);

for (int i = 0; i < formLL.getChildCount(); i++) {
   View child = formLL.getChildAt(i);

   if (child instanceof TextView) {
       TextView tv = (TextView) child;
       // ...
   }
}

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

  • 2 weeks later...
Posted

Epah, eu não posso, por artes mágicas adivinhar quais são os ids que tens nos ficheiros de interface, ou se estás a utilizar um LinearLayout ou outra coisa qualquer, logo parece-me óbvio que tens que adaptar o código às tuas necessidades.

Esse código serve para ir buscar o LinearLayout com o id 'formll', percorrer todos os elementos (child) que esse layout contém e, se for um TextView, faz o cast do objecto para TextView, para depois poderes realizar todas as operações que pretendas sobre a caixa de texto.

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.