我正在嘗試生成隨機數。爲此, 我從編輯文本中獲取文本並將其傳遞給Random類的nextInt。但我有一個問題。我的textView沒有改變。 這裏它的代碼:TextView未更新
package random.vivek.com.random;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by Shiva on 09-08-2015.
*/
public class Random extends AppCompatActivity {
int number , i ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
java.util.Random genertor = new java.util.Random();
EditText editText = (EditText) findViewById(R.id.random);
TextView textView = (TextView) findViewById(R.id.text);
String s = editText.getText().toString();
try {
i = Integer.parseInt(s);
for (int roll = 0; roll < 20; roll++) {
number = genertor.nextInt(i);
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
textView.setText(number + "");
}
}
已修復。謝謝。 :) –
是的,我剛剛意識到它並編輯我的帖子。那很愚蠢。再次感謝。 –