我打算用什么代码? [英] What codes am i going to use?

查看:74
本文介绍了我打算用什么代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将按钮更改为ImageButtons,我可以使用哪些代码,我可以使用图片而不是字母。这是我的代码仅使用按钮。



What codes am i going to use if i will change the buttons here into ImageButtons where i can play with pictures and not letters. Here's my code using Buttons only.

btn1 = (Button) findViewById(R.id.btn1);
       btn2 = (Button) findViewById(R.id.btn2);
       btn3 = (Button) findViewById(R.id.btn3);
       btn4 = (Button) findViewById(R.id.btn4);
       btn5 = (Button) findViewById(R.id.btn5);
       btn6 = (Button) findViewById(R.id.btn6);

       btn1.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               CheckButton(btn1, btn2);
               CheckButton(btn1, btn4);

           }
           });
           btn2.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               CheckButton(btn2, btn1);
               CheckButton(btn2, btn3);
               CheckButton(btn2, btn5);
           }
           });
           .........and so on.
   }

        private void CheckButton(final Button btn1, final Button btn2) {
                   if (btn2.getText().equals(""))
                   {
                       btn2.setText(btn1.getText().toString());
                       btn1.setText("");
                   }


            }







这是我的图像按钮代码,它有.setBackground(null)的问题。








Here's my codes for Image Buttons which has problems with ".setBackground(null)".


ibtn1 = (ImageButton) findViewById(R.id.ibtn1);
       ibtn2 = (ImageButton) findViewById(R.id.ibtn2);

       ibtn1.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               CheckiButton(ibtn1, ibtn2);


           }
           });
       ibtn2.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               CheckiButton(ibtn2, ibtn1);


           }
           });
private void CheckiButton(final ImageButton ibtn1, final ImageButton ibtn2) {
                   if (ibtn2.getBackground().equals(""))
                   {
                       ibtn2.setBackground(ibtn1.getBackground());
                       ibtn1.setBackgroundResource("");
                   }


            }

推荐答案

你还必须改变布局中的类型(在res \layout中找到)。它是XML,实际控件定义为Button,需要更改为ImageButton。



祝你好运!
You must also change the type in the layout (found in res\layout). It is XML and there the actual control is defined as Button and needs to be changed to ImageButton.

Good luck!


这篇关于我打算用什么代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆