Duplicate dialog box in android studio

-1

Good afternoon! I have a question on the android where I am creating an app to evaluate the mood of the user.

IcreatethecodeinsuchawaythatonlyoneoptionperdayisacceptedSonowIneedtoincludeawindowstatingthathehasalreadyperformedthetestifhehasalreadydoneitandneedthatafterhehasansweredopenadialogboxtoincludepersonalinformationsuchasphonenameetc.Hereisthecodethathasbeendonesofar:

publicclassActPrincipalextendsActivity{privateImageButtonibMuitoSatisfeito,ibSatisfeito,ibNeutro,ibInsatisfeito,ibMuitoInsatisfeito;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.act_principal);ibMuitoSatisfeito=(ImageButton)findViewById(R.id.ibMuitoInsatisfeito);ibSatisfeito=(ImageButton)findViewById(R.id.ibSatisfeito);ibNeutro=(ImageButton)findViewById(R.id.ibNeutro);ibInsatisfeito=(ImageButton)findViewById(R.id.ibInsatisfeito);ibMuitoInsatisfeito=(ImageButton)findViewById(R.id.ibMuitoInsatisfeito);ibMuitoSatisfeito.setOnLongClickListener(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(1);returntrue;}});ibSatisfeito.setOnLongClickListener(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(2);returntrue;}});ibNeutro.setOnLongClickListener(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(3);returntrue;}});ibMuitoInsatisfeito.setOnLongClickListener(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(5);returntrue;}});}publicvoidsalvarAvaliacao(intnro){Controladorcontrolador=newControlador(getBaseContext());Avaliacaoavaliacao=newAvaliacao();avaliacao.setDataAvaliacao(newSimpleDateFormat("dd/MM/yyyy").format(new Date()));
        avaliacao.setHorario(new SimpleDateFormat("HH:mm:ss").format(new Date()));
        avaliacao.setAvaliacao(nro);
        avaliacao.setEnviado(0);

        if (android.os.Build.VERSION.SDK_INT > 22) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 12);
        }
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

            Location localizacao = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);

            if (localizacao != null && ((new Date()).getTime() - localizacao.getTime()) / 1000 < 3600) {
                avaliacao.setLatitude(localizacao.getLatitude());
                avaliacao.setLongitude(localizacao.getLongitude());
            }
        }
        controlador.inserir(avaliacao);
        Toast.makeText(this, getString(R.string.msg_agradecimento), Toast.LENGTH_SHORT).show();
    }

    public void btAbrirActAvaliacao(View v) {
        startActivity(new Intent(this, ActAvaliacao.class));
    }
}
    
asked by anonymous 01.06.2016 / 20:41

1 answer

2

I believe that logic can be improved greatly. As I analyzed part of your code and realized that you are learning Android, I will suggest you to follow this script (I will not suggest you any more techniques):

2 Activities:

TestHumor (which displays options for voting). Personal data (with a layout with name, phone and email).

The main activity would be TestHumor. It is the MAIN activity of the application. When the user accesses to vote, you check if you have already voted today (by SQLite bank, SharedPreferences ... the medium does not matter). If you have already voted, you can have a textview-only layout that says that you have already voted. If not voted, loads the layout of voting layouts in the same XML. One you display (setVisibility) and the other you hide. Within the same layout XML you can work by displaying one and hiding the other (but this is not often recommended). After he has voted (if it is the first time, you load the Personal Data activity).

Always try to review your question in order to make it clear and concise. Very generic questions or asking for complete codes (solutions to your problem) can damage your reputation. Always try to be specific and study before asking because someone has already given a -1 in your doubt.

A hug and I hope I have helped.

    
01.06.2016 / 21:25