1. Textbox
2. RadioGroup
3. Button
Convert.java
package and.temperature;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class Convert extends Activity {
private EditText textInput;
private TextView textOutput;
private RadioGroup rdGroup;
private Float temp=0f;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textInput=(EditText)findViewById(R.id.textTemp);
textOutput=(TextView)findViewById(R.id.textOutput);
rdGroup=(RadioGroup)findViewById(R.id.radioGroup);
}
public void myClickHandler(View view){
switch(view.getId()){
case R.id.Button01:
try{
temp=new Float(textInput.getText().toString());
switch(rdGroup.getCheckedRadioButtonId())
{
case R.id.radioCelcius:
textOutput.setText(Float.toString(FarenhiteToCelcius(temp))+" C");
break;
case R.id.radioFarenhite:
textOutput.setText(Float.toString(CelciusToFarenhite(temp))+" F");
break;
}
}catch(Exception e)
{
Toast.makeText(this, "Invalid Input",
Toast.LENGTH_LONG).show();
}
break;
}
}
public float FarenhiteToCelcius(float temp){
return ((temp - 32) * 5 / 9);
}
public float CelciusToFarenhite(float temp){
return ((temp * 9) / 5) + 32;
}
public void Close(View view){
// Bundle bd = i.getExtras();
// if(bd.getInt("Close") == 1);
finish();
Log.v("DISPLAY", "closing convert");
}
}
I simply want to say I’m very new to blogs and actually loved you’re blog site. Almost certainly I’m going to bookmark your blog post . You absolutely come with great well written articles. Thanks a lot for sharing your blog.
ReplyDeleteandroid development course fees in chennai | android app development training in chennai|Android Training institute in chennai with placement