So i'm trying to do this : when you click the image the text in the center changes to a random element from the array but i want every element that appears once to not appear again... I tried doing it like this but it didn't work please help me here!!
package com.example.bibiwars.skills;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView img = (ImageView) findViewById(R.id.logo);
img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//ToastMessage to test the click ::::::
Toast.makeText(MainActivity.this, "Clicked!!",Toast.LENGTH_SHORT).show();
TextView text = (TextView) findViewById(R.id.text);
String[] Array = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
int rnd = new Random().nextInt(Array.length);
while (Array[rnd].equals("0"))
{rnd = new Random().nextInt(Array.length);}
text.setText(Array[rnd]);
Array[rnd] = "0";
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Aucun commentaire:
Enregistrer un commentaire