I'll do my best to explain what I want to accomplish; I feel if I could explain it better I wouldn't need to ask.
I want to select item from spinner, click one of the 4 buttons to send the spinner value (array value "Medications") to the next activity.
The values in "Medications" will have a string array of their own.
For EXAMPLE.
In "Medications" there is a value ENALAPRIL.
There is a string array "ENALAPRIL" that has 4 values,
HowString[0]
WhatString1
WhenString[2]
NotString[3]
In Activity2 there are only two TextView boxes.
The top TextView is for displaying the medication name selected from spinner
I CAN do this with no problem
The bottom TextView is for displaying a how, what, when, or not string - depending on which button was pressed to get to Activity2.
I need the bottom TextView to use a StringArray value dynamically that was passed with Intent:
"Medications" value(TextView1) selected needs to dynamically equal name of Array value used in (TextView2).
I am struggling with the context and how to phrase my needs so Apologies.
I hope that I am over-complicating something that is very, very simple.
Activity1 layout:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rxBox"
android:prompt="@string/rxprompt"
android:entries="@array/Medications"
android:focusable="true"
android:clickable="true"
android:visibility="visible"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center"
android:spinnerMode="dialog"
android:layout_centerHorizontal="true"
android:background="@drawable/abc_search_dropdown_dark"
android:popupBackground="@drawable/abc_ab_solid_light_holo"
android:layout_below="@+id/helprx" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/rxstudyinfo"
android:id="@+id/helprx"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textStyle="bold"
android:paddingStart="10dp"
android:visibility="visible"
android:textSize="20dp"
android:lines="5" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:paddingTop="50dp"
android:divider="@drawable/abc_ab_share_pack_holo_dark"
android:visibility="visible"
android:layout_below="@+id/rxBox">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dosing"
android:id="@+id/doseButton"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:enabled="true"
android:onClick="howRx" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/what"
android:id="@+id/whatButton"
android:clickable="true"
android:enabled="true"
android:onClick="whatRX" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/whenButton"
android:layout_gravity="center_horizontal"
android:text="@string/when"
android:clickable="true"
android:enabled="true"
android:onClick="whenRX" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/not"
android:id="@+id/notButton"
android:clickable="true"
android:enabled="true"
android:onClick="notRX" />
</LinearLayout>
Activity2 layout:
<TextView
android:text="MEDICATION NAME"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="35dp"
android:id="@+id/rxName"
android:paddingBottom="35dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="MEDICATION INFO"
android:id="@+id/infoRx" />
</LinearLayout>
CODE: Activity1
public class studyRX extends ActionBarActivity {
public void howRx(View view){
Spinner medChoice = (Spinner) findViewById(R.id.rxBox);
Intent howRxIntent = new Intent(getApplicationContext(),rxViewer.class);
Bundle b = new Bundle();
b.putString("medname",medChoice.getSelectedItem().toString());
howRxIntent.putExtras(b);
startActivity(howRxIntent);
//array index 0
}
CODE: Activity2
public class rxViewer extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rx_viewer);
Bundle b = this.getIntent().getExtras();
Resources r = getResources();
String medname = b.getString("medname");
((TextView)findViewById(R.id.rxName)).setText(medname);
// myString = getResources().getIdentifier(medname,"string",this.getPackageName());
//((TextView)findViewById(R.id.infoRx)).setText(bang);
//TextView t = (TextView)findViewById(R.id.infoRx);
//int maybe = getResources().getIdentifier(bang,"arrays",this.getPackageName());
Intent intentObject = getIntent();
}
XML:Medications
<string-array name="Medications">
<item>Enalapril</item>
<item>Captopril</item>
<item>Lisinopril</item>
<item>Ramipril</item>
<item>Adenosine</item>
<item>Amiodarone</item>
</string-array>
XML:Enalapril
<string-array name="Enalapril">
<item> String from HOW Button </item>
<item> String from WHAT Button </item>
<item> String from WHEN Button </item>
<item> String from NOT Button </item>
</string-array>
XML:Captopril
<string-array name="Captopril">
<item> String from HOW Button </item>
<item> String from WHAT Button </item>
<item> String from WHEN Button </item>
<item> String from NOT Button </item>
</string-array>
All medications are formatted the same so the Array index will relate to each button
THANK YOU!