我不能为可能的答案机器人工作室按钮 [英] I can not create buttons for possible answers android studio

查看:138
本文介绍了我不能为可能的答案机器人工作室按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

`

\r
\r

公共类Categoria延伸活动{\r
\r
    公共静态的String [] = nombre_cosa {cerdo,AVE,卡瓦略,科内霍,elefante,加伊纳,小鲨鱼,\r
            蛙,佩罗,帕托,oveja,莱昂,jirafa\r
            拉通,巴卡,AUTOBUS,automovil,阿维翁,bicicleta,camioneta,\r
            卡萨,celular,guitarra,motocicleta,康王,电视,杜拉斯诺,Fresa酒店,芒果\r
            UVAS,圣地亚,普拉塔诺,COCO,佩拉,Naranja酒店,曼札纳\r
            巴特,蝙蝠侠,脑,CHAVO,悟空,奥梅罗,玛吉\r
            帕特里西奥,珠光纸,菲尼亚斯,quico,蜘蛛侠,雷神,超人};\r
\r
    公共静态字符串[] sombra_cosa = {s_cerdo,s_ave,s_caballo,s_conejo,s_elefante,s_gallina,s_gato,\r
            s_rana,s_perro,s_pato,s_oveja,s_leon,s_jirafa,\r
            s_raton,s_vaca,s_autobus,s_automovil,s_avion,s_bicicleta,s_camioneta,\r
            \"s_casa\",\"s_celular\",\"s_guitarra\",\"s_motocicleta\",\"s_silla\",\"s_television\",\"s_durazno\",\"s_fresa\",\"s_mango\",\r
            s_uvas,s_sandia,s_platano,s_coco,s_pera,s_naranja,s_manzana,\r
            s_bart,s_batman,s_cerebro,s_chavo,s_goku,s_homero,s_marge,\r
            s_patricio,s_pepa,s_phineas,s_quico,s_spiderman,s_thor,s_superman};\r
\r
    公共静态布尔[] =国家体制{FALSE,假的,假的,假的,假的,假的,\r
            假的,假的,假的,假的,假的,假的,\r
            假的,假的,假的,假的,假的,假的,假的,\r
            假的,假的,假的,假的,假的,假的,假的,假的,\r
            假的,假的,假的,假的,假的,假的,假的,\r
            假的,假的,假的,假的,假的,假的,假的,假的,假的,假的,\r
            假的,假的,假的,假的,假的,假};\r
\r
    公共静态INT cosas_adivinadas = 0;\r
    私人INT intentos = 3;\r
    私人按钮aceptar;\r
    私人TextView的mensaje_intentos,mensaje_cuenta;\r
    私人的EditText usuario_cosa;\r
    私人INT numero_generado = 0;\r
    私人ImageView的miimagen;\r
    私人MediaPlayer的REPRODUCTOR;\r
    @覆盖\r
    保护无效的onCreate(捆绑savedInstanceState){\r
        super.onCreate(savedInstanceState);\r
        。getWindow()addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);\r
        requestWindowFeature(Window.FEATURE_NO_TITLE);\r
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);\r
        的setContentView(R.layout.activity_categoria);\r
        aceptar =(按钮)findViewById(R.id.btnaceptar);\r
        mensaje_intentos =(的TextView)findViewById(R.id.lblintentos);\r
        mensaje_cuenta =(的TextView)findViewById(R.id.lblcuenta);\r
        usuario_cosa =(EditText上)findViewById(R.id.txtcosa);\r
        miimagen =(ImageView的)findViewById(R.id.imgcosa);\r
        Cargar preferencias();\r
        新MiTarea()执行();\r
        REPRODUCTOR = MediaPlayer.create(这一点,R.raw.yansha);\r
        reproductor.setLooping(真);\r
        reproductor.start();\r
        mensaje_intentos.setText(Tiene+ intentos +intentos);\r
        aceptar.setOnClickListener(新View.OnClickListener(){\r
            @覆盖\r
            公共无效的onClick(视图v){\r
\r
                字符串农布雷= usuario_cosa.getText()的toString()与toLowerCase()。\r
                如果(nombre.equals(nombre_cosa [numero_generado]))\r
                {\r
                    establecer_cosa(numero_generado);\r
                    埃斯塔[numero_generado] = TRUE;\r
                    cosas_adivinadas ++;\r
                    esperar();\r
                }\r
                其他\r
                {\r
                    Toast.makeText(getApplicationContext(),Incorrecto,Toast.LENGTH_SHORT).show();\r
                    intentos = intentos-1;\r
                    mensaje_intentos.setText(Tiene+ intentos +intentos);\r
                }\r
\r
                如果(intentos == 0)\r
                {\r
                    卸妆preferencias();\r
                    意图I =新意图(Categoria.this,Perder.class);\r
                    startActivity(ⅰ);\r
                    完();\r
                }\r
            }\r
        });\r
    }\r
\r
    @覆盖\r
    保护无效onResume(){\r
        super.onResume();\r
        reproductor.start();\r
    }\r
\r
    公共无效esperar()\r
    {\r
        新CountDownTimer(5000,1000)\r
        {\r
\r
            @覆盖\r
            公共无效onTick(长millisUntilFinished){\r
                mensaje_cuenta.setText(Generando恩+(millisUntilFinished / 1000));\r
            }\r
\r
            @覆盖\r
            公共无效onFinish(){\r
\r
                如果(cosas_adivinadas == nombre_cosa.length)\r
                {\r
                    完();\r
                }\r
                其他\r
                {\r
                    新MiTarea()执行();\r
                    mensaje_cuenta.setText();\r
                    usuario_cosa.setText();\r
                }\r
            }\r
        }。开始();\r
    }\r
\r
    公共无效Cargar preferencias()\r
    {\r
        共享preferences MIS preferencias = getShared preferences(preferenciaCosa,Context.MODE_PRIVATE);\r
        intentos =误preferencias.getInt(intentos,3);\r
        cosas_adivinadas =误preferencias.getInt(adivinados,0);\r
        的for(int i = 0; I< nombre_cosa.length;我++)\r
        {\r
            埃斯塔[I] =误preferencias.getBoolean(nombre_cosa [I],FALSE);\r
        }\r
    }\r
\r
    公共无效和保存preferencias()\r
    {\r
        共享preferences MIS preferencias = getShared preferences(preferenciaCosa,Context.MODE_PRIVATE);\r
        共享preferences.Editor编辑错误= preferencias.edit();\r
        editor.putInt(intentos,intentos);\r
        editor.putInt(adivinados,cosas_adivinadas);\r
        的for(int i = 0; I< nombre_cosa.length;我++)\r
        {\r
            editor.putBoolean(nombre_cosa [I],埃斯塔[I]);\r
        }\r
        editor.commit();\r
    }\r
\r
    私人无效establecer_cosa(INT NUMERO)\r
    {\r
        INT渣油= getResources()则getIdentifier(nombre_cosa [NUMERO],绘制,getPackageName());\r
        miimagen.setImageResource(渣油);\r
    }\r
\r
    私人无效establecer_sombra(INT NUMERO)\r
    {\r
        INT渣油= getResources()则getIdentifier(sombra_cosa [NUMERO],绘制,getPackageName());\r
        miimagen.setImageResource(渣油);\r
    }\r
\r
\r
    私人无效卸妆preferencias()\r
    {\r
        共享preferences设置= getShared preferences(preferenciaCosa,Context.MODE_PRIVATE);\r
        。settings.edit()清()提交()。\r
    }\r
\r
    @覆盖\r
    保护无效的onStop(){\r
        如果(intentos == 0)\r
        {\r
            卸妆preferencias();\r
        }\r
        其他\r
        {\r
            和保存preferencias();\r
        }\r
        reproductor.pause();\r
        super.onStop();\r
    }\r
\r
    @覆盖\r
    保护无效的onDestroy(){\r
        如果(reproductor.isPlaying())\r
        {\r
            reproductor.stop();\r
            reproductor.release();\r
        }\r
        super.onDestroy();\r
    }\r
\r
    私有类MiTarea扩展的AsyncTask<太虚,太虚,太虚> {\r
        私人诠释valor_generado;\r
        @覆盖\r
        保护无效doInBackground(虚空...... PARAMS){\r
            做{\r
                valor_generado =((int)的(的Math.random()* nombre_cosa.length));\r
            }而(埃斯塔[valor_generado]);\r
            返回null;\r
        }\r
        @覆盖\r
        保护无效onPostExecute(虚空避免){\r
            numero_generado = valor_generado;\r
            establecer_sombra(valor_generado);\r
            super.onPostExecute(避免);\r
        }\r
    }\r
\r
\r
}

\r

\r
\r在这里,那里的阴影和图像运行​​的类的code

`你!是新来的Andr​​oid我有一个小的学校项目的一个问题是在Android的阴影工作室动物图画猜的东西等,但想我必须写名字,接受一个按钮,并准备图像亮灯,进入下一个应用程序,我要你给我任何答案的按钮说3键1是正确答案,其他两个假我花了很长时间与这甚至让我不能做到这一点,如果我能帮助我将AP preciate它提前极大的问候非常感谢你。我希望看到我的问题是清楚的问候


解决方案

创建一个变量是这样的:

 布尔isTextCorrect = FALSE;

在默认情况下,该按钮是不可见的。
实现一个监听器。如果在文本框文本改变了其正确的开关isTextCorrect为true,使按钮可见(可点击)。

 如果(isTextCorrect){
    button.setVisible(View.VISIBLE);
}

`

public class Categoria extends Activity {

    public static String[] nombre_cosa={"cerdo","ave","caballo","conejo","elefante","gallina","gato",
            "rana","perro","pato","oveja","leon","jirafa",
            "raton","vaca","autobus","automovil","avion","bicicleta","camioneta",
            "casa","celular","guitarra","motocicleta","silla","television","durazno","fresa","mango",
            "uvas","sandia","platano","coco","pera","naranja","manzana",
            "bart","batman","cerebro","chavo","goku","homero","marge",
            "patricio","pepa","phineas","quico","spiderman","thor","superman"};

    public static String[] sombra_cosa={"s_cerdo","s_ave","s_caballo","s_conejo","s_elefante","s_gallina","s_gato",
            "s_rana","s_perro","s_pato","s_oveja","s_leon","s_jirafa",
            "s_raton","s_vaca","s_autobus","s_automovil","s_avion","s_bicicleta","s_camioneta",
            "s_casa","s_celular","s_guitarra","s_motocicleta","s_silla","s_television","s_durazno","s_fresa","s_mango",
            "s_uvas","s_sandia","s_platano","s_coco","s_pera","s_naranja","s_manzana",
            "s_bart","s_batman","s_cerebro","s_chavo","s_goku","s_homero","s_marge",
            "s_patricio","s_pepa","s_phineas","s_quico","s_spiderman","s_thor","s_superman"};

    public static boolean[] estado={false,false,false,false,false,false,
            false,false,false,false,false,false,
            false,false,false,false,false,false,false,
            false,false,false,false,false,false,false,false,
            false,false,false,false,false,false,false,
            false,false,false,false,false,false,false,false,false,false,
            false,false,false,false,false,false};

    public static int cosas_adivinadas=0;
    private int intentos=3;
    private Button aceptar;
    private TextView mensaje_intentos,mensaje_cuenta;
    private EditText usuario_cosa;
    private int numero_generado=0;
    private ImageView miimagen;
    private MediaPlayer reproductor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_categoria);
        aceptar=(Button) findViewById(R.id.btnaceptar);
        mensaje_intentos=(TextView) findViewById(R.id.lblintentos);
        mensaje_cuenta=(TextView) findViewById(R.id.lblcuenta);
        usuario_cosa=(EditText) findViewById(R.id.txtcosa);
        miimagen=(ImageView) findViewById(R.id.imgcosa);
        CargarPreferencias();
        new MiTarea().execute();
        reproductor= MediaPlayer.create(this,R.raw.yansha);
        reproductor.setLooping(true);
        reproductor.start();
        mensaje_intentos.setText("Tiene " + intentos + " intentos");
        aceptar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String nombre=usuario_cosa.getText().toString().toLowerCase();
                if(nombre.equals(nombre_cosa[numero_generado]))
                {
                    establecer_cosa(numero_generado);
                    estado[numero_generado]=true;
                    cosas_adivinadas++;
                    esperar();
                }
                else
                {
                    Toast.makeText(getApplicationContext(), "Incorrecto", Toast.LENGTH_SHORT).show();
                    intentos=intentos-1;
                    mensaje_intentos.setText("Tiene " + intentos + " intentos");
                }

                if (intentos==0)
                {
                    removerPreferencias();
                    Intent i = new Intent(Categoria.this,Perder.class);
                    startActivity(i);
                    finish();
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        reproductor.start();
    }

    public void esperar()
    {
        new CountDownTimer(5000,1000)
        {

            @Override
            public void onTick(long millisUntilFinished) {
                mensaje_cuenta.setText("Generando en " + (millisUntilFinished/1000));
            }

            @Override
            public void onFinish() {

                if (cosas_adivinadas==nombre_cosa.length)
                {
                    finish();
                }
                else
                {
                    new MiTarea().execute();
                    mensaje_cuenta.setText("");
                    usuario_cosa.setText("");
                }
            }
        }.start();
    }

    public void CargarPreferencias()
    {
        SharedPreferences mispreferencias = getSharedPreferences("PreferenciaCosa", Context.MODE_PRIVATE);
        intentos=mispreferencias.getInt("intentos",3);
        cosas_adivinadas=mispreferencias.getInt("adivinados",0);
        for (int i=0;i<nombre_cosa.length;i++)
        {
            estado[i]=mispreferencias.getBoolean(nombre_cosa[i],false);
        }
    }

    public void GuardarPreferencias()
    {
        SharedPreferences mispreferencias = getSharedPreferences("PreferenciaCosa", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = mispreferencias.edit();
        editor.putInt("intentos",intentos);
        editor.putInt("adivinados",cosas_adivinadas);
        for (int i=0;i<nombre_cosa.length;i++)
        {
            editor.putBoolean(nombre_cosa[i], estado[i]);
        }
        editor.commit();
    }

    private void establecer_cosa(int numero)
    {
        int resId = getResources().getIdentifier(nombre_cosa[numero], "drawable", getPackageName());
        miimagen.setImageResource(resId);
    }

    private void establecer_sombra(int numero)
    {
        int resId = getResources().getIdentifier(sombra_cosa[numero], "drawable", getPackageName());
        miimagen.setImageResource(resId);
    }


    private void removerPreferencias()
    {
        SharedPreferences settings = getSharedPreferences("PreferenciaCosa", Context.MODE_PRIVATE);
        settings.edit().clear().commit();
    }

    @Override
    protected void onStop() {
        if (intentos==0)
        {
            removerPreferencias();
        }
        else
        {
            GuardarPreferencias();
        }
        reproductor.pause();
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        if (reproductor.isPlaying())
        {
            reproductor.stop();
            reproductor.release();
        }
        super.onDestroy();
    }

    private class MiTarea extends AsyncTask<Void, Void, Void> {
        private int valor_generado;
        @Override
        protected Void doInBackground(Void... params) {
            do {
                valor_generado=((int)(Math.random()*nombre_cosa.length));
            }while(estado[valor_generado]);
            return null;
        }
        @Override
        protected void onPostExecute(Void aVoid) {
            numero_generado = valor_generado;
            establecer_sombra(valor_generado);
            super.onPostExecute(aVoid);
        }
    }


}

Here the code of the class where the shadows and images run

`how are you! am new to Android I have a problem with a small school project is an app in android shadows studio on animal drawings guess things etc. But guess I have to write the name to accept a button and ready image lights up and goes to the next , what I want you to show me any answer with buttons say 3 button 1 is the correct answer and the other two false I took a long time with this and even I can not do it if I can help I would appreciate it immensely greetings in advance thank you very much . I hope to see my problem was clear greetings

解决方案

Create a variable like this:

boolean isTextCorrect = false;

In default, the button is invisible. Implement a listener. If the text in the textfield changed and its correct switch isTextCorrect to true and make the button visible (clickable).

if(isTextCorrect){
    button.setVisible(View.VISIBLE);
} 

这篇关于我不能为可能的答案机器人工作室按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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