Android 点击更改文本框文本

发布于 2024-11-25 11:54:48 字数 2382 浏览 0 评论 0原文

所以我有一个文本框,我想在单击时执行 ImageView,当您单击它时,文本框中的文本将会更改。我该怎么做?

我当前的代码是

Package com.momentum.snakeEncyclopedia;


import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

public class ballpython extends Activity implements View.OnClickListener {

//Variable for main image
ImageView display;

@Override
     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.ballpython);

        // Image Views set
        display = (ImageView) findViewById(R.id.ballpython2);
        ImageView image1 = (ImageView) findViewById(R.id.region);
        ImageView video = (ImageView) findViewById(R.id.video);
        ImageView home = (ImageView) findViewById(R.id.home);

        // Set on Click Listeners
        image1.setOnClickListener(this);
        video.setOnClickListener(this);
        home.setOnClickListener(this);

        }
// set the on clicks here
        public void onClick(View v) {
            switch (v.getId()) {

            case R.id.region:
                display.setImageResource(R.drawable.ballpython1);
                 findViewById(R.id.other).setVisibility(View.INVISIBLE);
                 findViewById(R.id.leftarrow).setVisibility(View.INVISIBLE);
                 findViewById(R.id.rightarrow).setVisibility(View.INVISIBLE);
                break;
            case R.id.video:
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                startActivity(browserIntent);
                break;
            case R.id.home:
                display.setImageResource(R.drawable.ballpython2);
                findViewById(R.id.leftarrow).setVisibility(View.VISIBLE);
                findViewById(R.id.rightarrow).setVisibility(View.VISIBLE);
                findViewById(R.id.other).setVisibility(View.VISIBLE);
                break;
            }

        }
        }

So i have a text box and i want to do a ImageView on click and when you click it the text in the textbox will change. how can i do this?

My current code is

Package com.momentum.snakeEncyclopedia;


import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

public class ballpython extends Activity implements View.OnClickListener {

//Variable for main image
ImageView display;

@Override
     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.ballpython);

        // Image Views set
        display = (ImageView) findViewById(R.id.ballpython2);
        ImageView image1 = (ImageView) findViewById(R.id.region);
        ImageView video = (ImageView) findViewById(R.id.video);
        ImageView home = (ImageView) findViewById(R.id.home);

        // Set on Click Listeners
        image1.setOnClickListener(this);
        video.setOnClickListener(this);
        home.setOnClickListener(this);

        }
// set the on clicks here
        public void onClick(View v) {
            switch (v.getId()) {

            case R.id.region:
                display.setImageResource(R.drawable.ballpython1);
                 findViewById(R.id.other).setVisibility(View.INVISIBLE);
                 findViewById(R.id.leftarrow).setVisibility(View.INVISIBLE);
                 findViewById(R.id.rightarrow).setVisibility(View.INVISIBLE);
                break;
            case R.id.video:
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                startActivity(browserIntent);
                break;
            case R.id.home:
                display.setImageResource(R.drawable.ballpython2);
                findViewById(R.id.leftarrow).setVisibility(View.VISIBLE);
                findViewById(R.id.rightarrow).setVisibility(View.VISIBLE);
                findViewById(R.id.other).setVisibility(View.VISIBLE);
                break;
            }

        }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-12-02 11:54:48

在您的用例场景中,您可以使用 XML 文件中的“onclick”属性。输入要调用的方法的名称(不带括号),然后以 View 作为唯一参数来实现该方法。

http://developer.android.com/resources/articles/ui-1.6.html
滚动到底部,您将看到使用示例。

In your use case scenario, you can use the "onclick" attribute in the XML file. Put in the name of the method you want to call (without parentheses) and then implement that method taking in a View as the only parameter.

http://developer.android.com/resources/articles/ui-1.6.html
Scroll to the bottom and you will see the usage example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文