• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How set Char ?

jagricek

Lurker
When I'm trying to change char in my word when I click on for example button A. I want a set char on A and change in my invisible word from (--) set A there where is his position. I'm generating code in NetBeans

if(hadanka.contains(pismeno))
{
for(int i=0;i!=hadanka.length();i++)
if(pismeno.equals(Character.toString(hadanka.charAt(i))))
{
prepsani=hadanka.charAt(i);

}

System.out.println(prepsani);;
}


Everything is ok. Hadanka is a guessing word and pismeno is the letter that I chose.
When I use it in my application for Android errors occur.

Here is my Android code:

public class MainActivity extends Activity implements OnClickListener {
int lvl1;
String[] Level1 = {"APPLE", "SAMSUNG", "NOKIA", "HTC"};
String odpoved, pokus;
char zvolenePismeno;

public void OnStart(View v) {
btnStart = (Button) findViewById(R.id.btnStart);
labOdpoved = (TextView) findViewById(R.id.labOdpoved);
Random rand = new Random();
lvl1 = Math.abs(rand.nextInt() % 3);
odpoved = Level1[lvl1];

char[] prepsani = new char[odpoved.length()];
for (int i = 0; i != odpoved.length(); i++) {
prepsani = '-';
}
labOdpoved.setText(String.valueOf(prepsani));
if (odpoved.contains(zvolenePismeno)) {
for (int i = 0; i != odpoved.length(); i++)
if (zvolenePismeno.equals(Character.toString(odpoved.charAt(i)))) {
prepsani = odpoved.charAt(i);
}
labOdpoved.setText(String.valueOf(prepsani));
}
}

public void kliknuti(Button btn) {
btn.setClickable(false);
btn.setVisibility(View.INVISIBLE);
}

public void OnA(View v) {
zvolenePismeno = 'A';
btn_A = (Button) findViewById(R.id.btn_A);
kliknuti(btn_A);
}
}
 
Back
Top Bottom