I have a text file which contains all five-letter words in Turkish. From there, I want to draw a random word. AssetManager screen printing on all of the word, but somehow I did not drop a single word. How can I use a loop?
I would be glad if you can help.
Source:
public class MainActivity extends Activity {
    Button degistir;
    TextView kelime;
    EditText ykelime;
    Random rnd =new Random();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        degistir=(Button)findViewById(R.id.btngiris);
        kelime=(TextView)findViewById(R.id.kelime);
        ykelime=(EditText)findViewById(R.id.giris);
        AssetManager assetManager = getAssets();
        // To load text file
        InputStream input;
        try {
            input = assetManager.open("5HarfliKelimeler.txt");
            int size = input.available();
            byte[] buffer = new byte[size];
            input.read(buffer);
            input.close();
            // byte buffer into a string
            String text = new String(buffer);
            int sayi=rnd.nextInt(text.length());
            kelime.setText(text);
        } 
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        degistir.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                kelime.setText(ykelime.getText());
                ykelime.setText(null);
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}
 
     
     
     
    