This is the code I added to my project...
// Main program functions starts from here
// Find Id's and set variables
{
final EditText fp = (EditText) findViewById(R.id.fuelprice);
final EditText fC = (EditText) findViewById(R.id.fuelcunsumption);
final EditText drive = (EditText) findViewById(R.id.rangetodrive);
final TextView totalcost = (TextView) findViewById(R.id.totalcost);
Button CalcBtn = (Button) findViewById(R.id.CalcButton);
CalcBtn.setOnClickListener(new View.OnClickListener()
{
@override
public void onClick(View view)
{
// Converting strings to float
String n1 = fp.getText().toString();
float no1 = Float.parseFloat(n1);
String n2 = fC.getText().toString();
float no2 = Float.parseFloat(n2);
String n3 = drive.getText().toString();
float no3 = Float.parseFloat(n3);
// Calculates the floats
float calc = no1 * no2 * no3;
// Converting and prints out the result
String sum = Float.toString(calc);
totalcost.setText(sum);
}
});
Button ResetBtn = (Button) findViewById(R.id.ResetButton);
ResetBtn.setOnClickListener(new View.OnClickListener()
{
// ResetButton Resets the textViews
@override
public void onClick (View view)
{
fp.setText("");
fC.setText("");
drive.setText("");
totalcost.setText("0");
}
});
Since it didnt work out, I made a new project just to try with 1 textview and 1 button.
This is that code:
TextView ShowText = (TextView) findViewById(R.id.testText);
public void PltextBtn(View button) {
ShowText.setText("Test Text");
}
Both cases showed same problem in the genymotion emulator.
Hope to solve this soon!