0
有人可以告訴我在這段代碼中我錯了什麼,因爲我在clicklistener上不工作,並且從0到1的數字沒有出現。設置一個OnClickListener
public class FunFactsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
Button showFactButton = (Button)findViewById(R.id.showFactButton);
button.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
TextView factTextView =
(TextView)findViewById(R.id.factTextView);
factTextView.setText("button clicked ");
}
}
);
//declare are View variables and assign the views from the layout file
final TextView factLabel = (TextView) findViewById(R.id.factTextView);
View.OnClickListener Listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//the button was clicked, so update the fact label with a new fact
String fact = "";
// randomly select a fact
Random randomGenerator = new Random();//construct a new random generator
int randomNumber = randomGenerator.nextInt(3);
仍然停留我將上傳代碼加載,這是現在混亂 – user1727257