New to android here. I intend to make an app that has a ListView with Radio buttons set in single choice mode. After the user selects a radio button for the corresponding ListView item, and after clicking a Button input, it should take the user to another activity.
As such I am having trouble as to how I should approach the problem of how to define a RadioGroup which fetches the values of RadioButton dynamically from the strings.xml file.
This is the related work that I have at the moment pertaining to this;
Related Code in MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Array of place types
mPlaceType = getResources().getStringArray(R.array.place_type);
// Array of place type names
mPlaceTypeName = getResources().getStringArray(R.array.place_type_name);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, mPlaceTypeName); //ArrayAdapter<String> means each element in the array would be a string
mListPlaceType = (ListView) findViewById(R.id.list_place_type);
mListPlaceType.setAdapter(adapter);
mListPlaceType.setItemsCanFocus(false);
mListPlaceType.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Intent mIntent = getIntent();
main_radius = mIntent.getIntExtra("radius", 0);
//TextView
TextView tV = (TextView)findViewById(R.id.textView_main);
tV.setText("Current Radius is: " +Integer.toString(main_radius));
Button btnFind;
// Getting reference to Find Button
btnFind = ( Button ) findViewById(R.id.btn_find);
// Setting click event listener for the find button
btnFind.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder sb1 = new StringBuilder(sbMethod());
Intent mapIntent = new Intent(getApplicationContext(), MapActivity.class);
Bundle b = new Bundle();
b.putString("sb1",sb1.toString());
mapIntent.putExtras(b);
startActivity(mapIntent);
if(mListPlaceType.getSelectedItemPosition() < 0 )
{
Toast.makeText(getApplicationContext(), "No Item Selected from List", Toast.LENGTH_LONG).show();
}
}
});
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
style="@style/LinearLayout">
<Button
android:id="@+id/btn_find"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="@string/str_btn_find"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ListView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/list_place_type"
android:layout_below="@+id/btn_find"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView_main"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
strings.xml
<resources>
<string name="app_name">GeoGuideB</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="str_btn_find">Find</string>
<string name="change_radius">Change Radius</string>
<string name="save_radius">Save Radius</string>
<string-array name="place_type">
<item>airport</item>
<item>atm</item>
<item>bank</item>
<item>bus_station</item>
<item>church</item>
<item>doctor</item>
<item>hospital</item>
<item>movie_theater</item>
<item>restaurant</item>
</string-array>
<string-array name="place_type_name">
<item>Airport</item>
<item>ATM</item>
<item>Bank</item>
<item>Bus Station</item>
<item>Church</item>
<item>Doctor</item>
<item>Hospital</item>
<item>Movie Theater</item>
<item>Restaurant</item>
</string-array>
At the moment I have this layout:
for my app and on clicking the 'Find' button it should jump from this activity to the next one. Considering this, what should be the approach I should follow? Thanks.