I'm new to android development using eclipse and I wonder if someone could me give some tips on how to do this little apps of mine. What I want to do is to display in text view the data or value of a selected item in the spinner. For example I have a spinner with an array of hex data 1 to F. Data F for example corresponds to an error message like " this is an error message ". When I select the data F in my spinner it will display the message "this is an error message" in the textview. I will be using several spinners and each has its own hex data and values. I wanted to be able to select from one or more spinners a hex data and display the corresponding values in text view. Below is my xml code that I started. Right now there's only 2 spinners but there will be 10 in total. Textview 1 is where I wanted the message to be diplayed.
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:ba开发者_如何学Gockground="@drawable/pcb" android:orientation="vertical">
<TextView android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:id="@+id/textView2"
android:text="Error message"
android:layout_marginTop="20dp"
android:textColor="#ff000000"
android:textSize="15dp"
android:typeface="monospace"
android:textStyle="bold"
></TextView>
<TextView android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0"
android:textColor="#ff000000"
android:textStyle="bold"
android:typeface="serif"
android:visibility="visible"
android:textSize="15dp"
android:height="100dp"
android:width="200dp"
android:text=""
android:layout_marginTop="20dp"
></TextView>
<TextView android:id="@+id/textView3"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:textColor="#ff000000"
android:textStyle="bold" android:text="mycode"></TextView>
<TextView android:layout_width="match_parent"
android:id="@+id/textView4"
android:layout_height="wrap_content"
android:textColor="#ff000000"
android:typeface="monospace"
android:textStyle="bold"
android:text="BYTE 1 2 3 4 5 6 7 8 9 10"
></TextView>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2">
<Spinner android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/hexicon"
android:entries="@array/hex"
android:layout_marginLeft="47dp"
></Spinner>
<Spinner android:layout_width="wrap_content"
android:background="@drawable/hexicon"
android:entries="@array/hex"
android:layout_height="wrap_content"
android:id="@+id/spinner2"
android:layout_marginLeft="9dp"></Spinner>
</LinearLayout>
</LinearLayout>
Would greatly appreciate any ideas of how this can be done, if what I'm planning is not even possible. Sorry, I can't post an image yet. Thanks in advance.
freeman
You can add a OnItemClickListener
to your Spinners and from there get the data for your TextView
On a Spinner call setOnItemClickListener() to a listener implemented by you.
In your implementation you will have a onItemClick(AdapterView<?> parent, View view, int position, long id)
method.
Inside this you can call getItem(position) on the Adapter to get the item selected and therefore get the data from there and put it in the TextView through setText()
Hope it helps, JQCorreia
精彩评论