Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: Skrátenie vypisovania

V předchozím kvízu, Online test znalostí Java, jsme si ověřili nabyté zkušenosti z kurzu.

Aktivity
Avatar
Tomáš Šálek:13.6.2017 17:36

Nedalo by sa nejako skrátiť vypisovanie na jednoduhšie ako toto:

Button mBT1=(Button) findViewById(R­.id.button1);
Button mBT2=(Button) findViewById(R­.id.button2);
Button mBT3=(Button) findViewById(R­.id.button3);
Button mBT4=(Button) findViewById(R­.id.buttonPLS);
Button mBT5=(Button) findViewById(R­.id.button5);
Button mBT6=(Button) findViewById(R­.id.button6);
Button mBT7=(Button) findViewById(R­.id.button7);
Button mBT8=(Button) findViewById(R­.id.buttonMNS);
Button mBT9=(Button) findViewById(R­.id.button9);
Button mBT10=(Button) findViewById(R­.id.button10);
Button mBT11=(Button) findViewById(R­.id.button11);
Button mBT12=(Button) findViewById(R­.id.buttonKRT);
Button mBT13=(Button) findViewById(R­.id.button13);
Button mBT14=(Button) findViewById(R­.id.button14);
Button mBT15=(Button) findViewById(R­.id.button15);
Button mBT16=(Button) findViewById(R­.id.buttonDLN);
Button mBT17=(Button) findViewById(R­.id.buttonAC);
Button mBT18=(Button) findViewById(R­.id.button18);
Button mBTMo=(Button) findViewById(R­.id.buttonMo);
Button mBTOD=(Button) findViewById(R­.id.buttonOd);

 
Odpovědět
13.6.2017 17:36
Avatar
Odpovídá na Tomáš Šálek
Petr Štechmüller:13.6.2017 18:46

Můžeš si vytvořit pole ID tlačítek a pak pole tlačítek.

Button[] tlačítka;
int[] idTlacitek;

for(int i=0) {
  tlačítka[i] = (Button)findViewById(idTlacitek[i];
}
Akceptované řešení
+20 Zkušeností
+2,50 Kč
Řešení problému
Nahoru Odpovědět
13.6.2017 18:46
Pokud spolu kód a komentář nekorespondují, budou patrně oba chybné
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 2 zpráv z 2.