安卓开发时,生成一个七位的字母与数字混合的随机字符串作为验证码= = 我都没给注释,就这样吧 package hey.world; import java.util.Random; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class NewWorld extends Activity { /** Called when the activity is first created. */ public TextView titleView; private Button selectbtn; public static String getRandomString(int len){/**生成随机字符串*/ String Vertification=""; char[] ch=new char[len]; Random rd=new Random(); for(int i=0;i<len;i++){ if (rd.nextBoolean()== true) ch[i]=(char)(rd.nextInt(25)+97); else ch[i]=(char)(rd.nextInt(9)+48); } Vertification=new String(ch); return Vertification; } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); titleView = (TextView) findViewById(R.id.editText1); titleView.setText(getRandomString(7)); selectbtn = (Button)findViewById(R.id.select1); selectbtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub setContentView(R.layout.main); Intent intent = new Intent(); intent.setClass(NewWorld.this,openFile.class); startActivity(intent); } }); } }