![](/img/trans.png)
[英]How to use randomization, so when you press a button it brings you to a random screen
[英]How do you change the screen so that when you click anywhere on the screen, you go from the problem to the answer?
我有一個數學問題,即1 + 1。 如何更改應用程序屏幕,以便在單擊屏幕時將屏幕從1 + 1更改為一個數字2?
我創建了幾個文本視圖和一個水平分隔線。 我是Java的新手,只知道javascript。
您需要將OnClickListener
設置為TextView
並更改文本。
textview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textview.setText("2");
}
});
現在TextView
變化上的點擊文本TextView
。 很難理解,但我認為您想在隨機點擊位置上更改文本。 因此,將OnClickListener
設置為主布局。
XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="@+id/layout"
android:layout_height="match_parent">
//Your TextViews...
</LinearLayout>
JAVA
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textview.setText("2");
}
});
不要忘記聲明變量。
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
Textview textview= (Textview)findViewById(R.id.textview);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.