Java 如何在android的textview上随机生成24个字符串值?
我想在24 textview上生成24个字符串值,我在android中创建了xml文件,还为getid和set listener编写了代码,但这里没有提到。 在overrideoncick方法中,我定义了clickfun方法。 在这段代码中,我只是为整数值编码,但现在我想从字符串数组中进行比较,该数组具有如下静态值 字符串[]值={11,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22}; 请帮我解决我的问题Java 如何在android的textview上随机生成24个字符串值?,java,android,random,Java,Android,Random,我想在24 textview上生成24个字符串值,我在android中创建了xml文件,还为getid和set listener编写了代码,但这里没有提到。 在overrideoncick方法中,我定义了clickfun方法。 在这段代码中,我只是为整数值编码,但现在我想从字符串数组中进行比较,该数组具有如下静态值 字符串[]值={11,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22}; 请帮我解决我的问题
public class GameDemo extends Activity implements AnimationListener, OnClickListener
{
FrameLayout iv1,iv2,iv3,iv4,iv5,iv6,iv7,iv8,iv9,iv10,iv11,iv12,iv13,iv14,iv15,iv16,iv17,iv18,iv19,iv20,iv21,iv22,iv23,iv24;
TextView tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10,tv11,tv12,tv13,tv14,tv15,tv16,tv17,tv18,tv19,tv20,tv21,tv22,tv23,tv24;
Animation an1,an2;
int i1,counter,score,rev_count,level_counter;
boolean r_c,s_c;
Integer[] no;
FrameLayout[] count,rem,revise;
final Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_demo);
an1 = AnimationUtils.loadAnimation(this,R.anim.flip1);
an1.setAnimationListener(this);
an2 = AnimationUtils.loadAnimation(this,R.anim.flip1);
an2.setAnimationListener(this);
level_counter=24;
getIDForAll();
setListnerForAll();
counter=1;
rev_count=0;
no = new Integer[25];
count = new FrameLayout[3];
rem = new FrameLayout[3];
revise = new FrameLayout[8];
int i=0;
for(i=0 ; i<24 ; i++)
{
Random r = new Random();
i1 = r.nextInt(25 - 1) + 1;
if(i!=0)
{
while(Arrays.asList(no).contains(i1))
{
r = new Random();
i1 = r.nextInt(25 - 1) + 1;
}
no[i]= i1 ;
}
else
{
no[i]= i1 ;
}
}
public void click_fun(FrameLayout arg0, TextView arg1, int n)
{
if(counter<2)
{
arg0.setAnimation(an1);
if(no[n]<=12)
{
arg1.setText(""+no[n]);
arg0.setBackgroundResource(android.R.color.white);
}
else
{
arg1.setText(""+(no[n]-12));
arg0.setBackgroundResource(android.R.color.white);
}
arg0.setTag(no[n]);
count[counter] = arg0;
counter++;
Log.i("animate", "anim2");
}
else
{
Log.i("animate", "animo1");
arg0.setAnimation(an1);
if(no[n]<=12)
{
arg1.setText(""+no[n]);
arg0.setBackgroundResource(android.R.color.white);
}
else
{
arg1.setText(""+(no[n]-12));
arg0.setBackgroundResource(android.R.color.white);
}
arg0.setTag(no[n]);
count[counter] = arg0;
counter++;
Log.i("animate", "animo2");
Uri uri = Uri.parse("android.resource://com.game/drawable/ic_launcher");
int temp1 = (Integer) count[1].getTag();
int temp2 = (Integer) arg0.getTag();
Log.i("animate", "animo3");
if((temp1-temp2)==-12 || temp1-temp2==12)
{
rem[1]=count[1];
rem[2]=count[2];
s_c=true;
score=score+10;
score_lbl.setText("Score : "+score);
score=score+10;
score_lbl.setText("Score : "+score);
level_counter=level_counter-2;
}
else
{
rev_count++;
revise[rev_count]=count[1];
rev_count++;
revise[rev_count]=count[2];
r_c=true;
score=score-2;
score_lbl.setText("Score : "+score);
}
counter=1;
}
公共类GameDemo扩展活动实现AnimationListener、OnClickListener
{
框架布局iv1、iv2、iv3、iv4、iv5、iv6、iv7、iv8、iv9、iv10、iv11、iv12、iv13、iv14、iv15、iv16、iv17、iv18、iv19、iv20、iv21、iv22、iv23、iv24;
TextView tv1、tv2、tv3、tv4、tv5、tv6、tv7、tv8、tv9、tv10、tv11、tv12、tv13、tv14、tv15、tv16、tv17、tv18、tv19、tv20、tv21、tv22、tv23、tv24;
动画an1、an2;
int i1,计数器,分数,版本计数,级别计数器;
布尔r_c,s_c;
整数[]否;
框架布局[]计数、rem、修订;
最终上下文=此;
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u game\u demo);
an1=AnimationUtils.loadAnimation(this,R.anim.flip1);
an1.setAnimationListener(此);
an2=AnimationUtils.loadAnimation(这是R.anim.flip1);
an2.setAnimationListener(此);
电平计数器=24;
getIDForAll();
setListnerForAll();
计数器=1;
rev_计数=0;
否=新整数[25];
计数=新的帧布局[3];
rem=新的框架布局[3];
修订=新框架布局[8];
int i=0;
因为(i=0;i我认为我不完全了解你的情况。
1.创建字符串资源数组:
private Integer[] Strings = { many, strings, R.string.stringa };
2.调用方法获取随机资源:
getRandomString(int);
3.返回一个随机字符串:
private String getRandomString(int random)
return getString( Strings[ random ] );