спасибо за помощь, я изучаю программирование с помощью java и android, моя проблема в том, что я разрабатываю приложение, которое преобразует от миль до км и наоборот и показывает результат в середине экран в большом количестве, но при ударе конвертировать результат равен 0.0, я хочу знать, как отображать результат.Android App display 0.0 вместо результата
вот мой код
//Method called when click the button
public void onClick(View view) {
switch (view.getId()){
case R.id.radioButton:
RadioButton milesButton = (RadioButton) findViewById(R.id.radioButton);
RadioButton kmButton = (RadioButton) findViewById(R.id.radioButton2);
if(text.getText().length() == 0) {
Toast.makeText(this, "Please enter a valid number", Toast.LENGTH_LONG).show();
return;
}
}
Double inputValue = Double.parseDouble(text.getText().toString());
RadioButton rb = (RadioButton) findViewById(R.id.radioButton);
RadioButton rb2 = (RadioButton) findViewById(R.id.radioButton2);
if (rb.isChecked()) {
text.setText(String.valueOf(Conversor.convertMilesToKm(inputValue)));
rb.setChecked(false);
rb2.setChecked(true);
} else {
text.setText(String.valueOf(Conversor.convertKmToMiles(inputValue)));
rb2.setChecked(false);
rb.setChecked(true);
}
}
Это мой main.xml файл
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >
<EditText
android:gravity="center"
android:id="@+id/conversion_number"
android:hint="@string/in_message"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="numberSigned|numberDecimal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:ems="10"
android:layout_marginTop="31dp"
android:layout_toLeftOf="@+id/button" />
<Button
android:text="@string/convert"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="onClick"
android:layout_alignBottom="@+id/conversion_number"
android:layout_alignParentRight="true"
android:layout_marginRight="31dp"
android:id="@+id/button" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/conversion_number"
android:layout_alignParentLeft="true"
android:layout_marginLeft="33dp"
android:layout_marginRight="175dp"
android:layout_marginBottom="380dp"
android:id="@+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Miles"
android:id="@+id/radioButton"
android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Kilometers"
android:id="@+id/radioButton2" />
</RadioGroup>
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:padding="10dip"
android:layout_marginTop="150dip"
android:layout_marginBottom="20dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="false"
android:visibility="visible">
<TextView
android:id="@+id/bigText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bigText"
android:textSize="150dip"
android:focusable="false"
android:typeface="normal" />
</LinearLayout>
Мой класс преобразования
package com.algenis.speedcoverter;
public class Conversor {
//convert to miles
public static double convertMilesToKm(double miles) {
double miles_rand;
miles_rand = (miles * 1.60934);
return (int)Math.round(miles_rand);
}
// convert to km
public static double convertKmToMiles(double km) {
double km_rand;
km_rand = (km * 0.621371);
return (int)Math.round(km_rand);
}
}
Что такое значение 'inputValue'? (И просто используйте «double», вы ненужно создаете и отбрасываете объект-оболочку.) – chrylis
Я хочу показать свой результат в середине экрана, как вы видите на этом изображении. [Нажмите здесь] (http://i1356.photobucket.com/albums/q723/algenisromero/Android%20Apps/device-2013-12-22-124740_zps3eaefaaa.png) – Algenis
@ Алген, может быть, вы хотите выбрать правильный ответ? –