在旋转选择如何显示对应于一个项目数据 [英] how to display data corresponding to an item selected in a spinner

查看:189
本文介绍了在旋转选择如何显示对应于一个项目数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用eclipse是新的android开发,我不知道,如果有人我可以给就怎么做我的这个小应用程序的一些技巧。
我想要做的就是在要显示的文字查看微调所选项目的数据或值。例如我有十六进制数据1的阵列F.数据F一微调,例如对应于诸如这是一个错误消息的错误消息。当我选择了数据F在我的微调会显示消息这是一个错误消息在TextView中。我会用一些纺纱厂,每个人都有自己的十六进制数据和值。我希望能够从一个或多个纺纱选择一个十六进制数据,并在文本视图中显示相应的值。下面是我的XML code,我开始了。现在这里只有2纺纱厂,但会有10总。 TextView的1就是我想是diplayed消息。

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:background="@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> 

将大大AP preciate如何可以做到这一点,如果有什么我打算甚至是不可能的任何想法。对不起,我不能发表图片呢。
先谢谢了。

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.

民丰

推荐答案

您可以添加 OnItemClickListener 您纱厂,并从那里得到的数据为您的TextView

You can add a OnItemClickListener to your Spinners and from there get the data for your TextView

在一个微调通话setOnItemClickListener()由你实现了一个监听器。
在你实现你将有一个 onItemClick(适配器视图&LT;&GT;母公司,观景,INT位置,长的ID)。

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.

这里面,你可以在适配器调用getItem(位置),以获得该项目选定,因此从那里得到的数据,并把它在TextView中通过的setText()

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()

希望它能帮助,
JQCorreia

Hope it helps, JQCorreia

这篇关于在旋转选择如何显示对应于一个项目数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆