Radiobutton value to EditText space



Hi guys I am trying to get it so the user will be able to pick units for a calculation.


I am just Radio buttons and I am trying to select a radiobutton, get the value of the string that is stored there and have that displayed.


So far i am getting my options to come up and when I got to Set he value that app crashes.


Any ideas or help would be great!


Java class



public void Un()
{

Mq = (EditText) findViewById(R.id.u1);
EditText c = (EditText) findViewById(R.id.u1);
c.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
show2();
}
});
}
public void show2() {

final Dialog h = new Dialog(Sol.this);
h.setTitle("Units");
h.setContentView(R.layout.molunit);
Button b1 = (Button) h.findViewById(R.id.b1);
Button b2 = (Button) h.findViewById(R.id.b2);


b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

RadioGroup types = (RadioGroup) findViewById(R.id.radioUnits);

switch (types.getCheckedRadioButtonId()) {

// case R.id.M:
case R.id.M:
Mq.setText("M");
// h.dismiss();


case R.id.mM:

Mq.setText("mM");
// h.dismiss();


case R.id.uM:
Mq.setText("M");
// h.dismiss();

case R.id.pM:


Mq.setText("M");
// h.dismiss();

case R.id.cM:

Mq.setText("M");
// h.dismiss();

}

}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
h.dismiss();
}
});
h.show();
}


Main.xml



<EditText
android:id="@+id/u1"
android:background="@android:color/holo_red_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/Text1"
android:layout_above="@+id/Text2"
android:layout_toRightOf="@+id/button5"
android:layout_toEndOf="@+id/button5"
android:inputType="textAutoComplete"
/>


Units.xml



<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="match_parent">

<RadioGroup
android:id="@+id/radioUnits"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RadioButton
android:layout_width="match_parent"
android:layout_height="75dp"
android:text="@string/M"
android:id="@+id/M"
android:layout_gravity="center_horizontal"
android:checked="true" />

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/mM"
android:inputType="text"
android:id="@+id/mM"
android:layout_gravity="center_horizontal"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/uM"
android:id="@+id/uM"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/pM"
android:id="@+id/pM"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/cM"
android:id="@+id/cM"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09"/>

</RadioGroup>

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set"
android:layout_weight="0.15"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="68dp"
android:layout_marginBottom="133dp" />

<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_gravity="right"
android:layout_alignTop="@+id/b1"
android:layout_toRightOf="@+id/b1"
android:layout_toEndOf="@+id/b1"
android:layout_marginLeft="77dp" />

</RelativeLayout>

No comments:

Post a Comment