簡體   English   中英

如何更改屏幕,以便在單擊屏幕上的任意位置時都能從問題中找到答案?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM