TextView not showing on Android device?

I have several views in a linear layout. After pressing the button, the math is performed. The result is then displayed as text. It works fine on the emulator, but it doesn't work on my android device.

Whole layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/text_enter"
    android:textSize="20sp" />

<EditText
    android:id="@+id/num"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:inputType="number" >

    <requestFocus />
</EditText>

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/num" >

<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/radio_celsius"
    android:onClick="onRadioButtonSelectUnit" />

<RadioButton
    android:id="@+id/radioButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/radio_fahrenheit"
    android:onClick="onRadioButtonSelectUnit" />

</RadioGroup>

<Button
    android:id="@+id/convert"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/radioGroup1"
    android:onClick="onClickConvert"
    android:text="@string/button_convert" />

    <TextView
    android:id="@+id/answer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/convert"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="22dp"
    android:layout_marginTop="17dp"
    android:layout_toLeftOf="@+id/convert"
    android:textColor="#000000"
    android:textSize="20sp"
    android:ellipsize="end" />

<TextView
    android:id="@+id/unit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/answer"
    android:layout_toRightOf="@+id/answer"
    android:textColor="#000000"
    android:textSize="20sp" />


</RelativeLayout>

      

This is part of the onClick event:

double result;
if(unitSelected.isChecked()){
        EditText number = (EditText)findViewById(R.id.num);
        TextView converted = (TextView)findViewById(R.id.answer);
        TextView unit = (TextView)findViewById(R.id.unit);
        result = Double.parseDouble(number.getText().toString()) * 9/5 + 32;
        String finalResult = String.valueOf(result);
        converted.setText(finalResult);
        Toast.makeText(this,String.valueOf(result), Toast.LENGTH_LONG).show();
        unit.setText("Fahrenheit");
        return;
    }
    else {
        EditText number = (EditText)findViewById(R.id.num);
        TextView converted = (TextView)findViewById(R.id.answer);
        TextView unit = (TextView)findViewById(R.id.unit);
        result = (Double.parseDouble(number.getText().toString()) - 32) * 5/9;
        String finalResult = String.valueOf(result);
        converted.setText(finalResult);
        unit.setText("Celsius");
        return;
    }

      

I had a setup differently before, without using a finalResult String, but was trying to try something different to try and get it to work. The toast was just to make sure the math was done correctly. It. The unit.setText () function works fine, but the answer won't appear next to it. It works on the emulator, not my device (note 4).

+3


source to share


1 answer


Delete android:layout_toLeftOf="@+id/convert"

the "id / answer" text box. Not entirely sure about the mismatch between devices, but it looks like it is now lining up.



Also, I think there is a typo in <requestFocus />

+1


source







All Articles