I'm trying to set the variable txtMedia1
to the value of the variable media1
. I did this, but Android Studio
indicates that I have to change txtMedia1 to double
or media1
to TextView
:
package com.app.jeffersonalencar.composicao;
import android.renderscript.Double2;
import android.renderscript.Sampler;
import android.support.annotation.StringDef;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;
public class act_mains extends AppCompatActivity implements View.OnClickListener{
//Declarando variáveis de coleta de medida
public EditText edtTxt1, edtTxt2, edtTxt3;
//Declarando campo de visualização da média por parte
public TextView txtMedia1;
//Declarando botão
public Button btnMedia1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_main);
//Setando os valores dos campos de coleta para as variáveis
edtTxt1 = (EditText) findViewById(R.id.edtTxt1);
edtTxt2 = (EditText) findViewById(R.id.edtTxt2);
edtTxt3 = (EditText) findViewById(R.id.edtTxt3);
}
public void onClick(View V){
double medida1 = Double.parseDouble(edtTxt1.getText().toString());
double medida2 = Double.parseDouble(edtTxt2.getText().toString());
double medida3 = Double.parseDouble(edtTxt3.getText().toString());
double media1 = (medida1 + medida2 + medida3)/3;
//Terminar a briga e colocar o valor no TextView
String media2 = String.valuesOf(media1);
txtMedia1 = (TextView) getText(R.id.media2) ;
}
}
Realizing what Android Studio
still asks for error.