Android 如何显示与微调器中所选项目对应的数据
我是使用eclipse进行android开发的新手,我想知道是否有人能给我一些关于如何使用我的这些小应用程序的提示。 我要做的是在文本视图中显示微调器中选定项的数据或值。例如,我有一个带有十六进制数据1到F数组的微调器。例如,数据F对应一条错误消息,如“这是一条错误消息”。当我在微调器中选择数据F时,它将在文本视图中显示消息“这是一条错误消息”。我将使用几个微调器,每个微调器都有自己的十六进制数据和值。我希望能够从一个或多个微调器中选择十六进制数据,并在文本视图中显示相应的值。下面是我开始编写的xml代码。现在只有2个纺纱机,但总共将有10个。Textview 1是我希望显示消息的地方Android 如何显示与微调器中所选项目对应的数据,android,spinner,Android,Spinner,我是使用eclipse进行android开发的新手,我想知道是否有人能给我一些关于如何使用我的这些小应用程序的提示。 我要做的是在文本视图中显示微调器中选定项的数据或值。例如,我有一个带有十六进制数据1到F数组的微调器。例如,数据F对应一条错误消息,如“这是一条错误消息”。当我在微调器中选择数据F时,它将在文本视图中显示消息“这是一条错误消息”。我将使用几个微调器,每个微调器都有自己的十六进制数据和值。我希望能够从一个或多个微调器中选择十六进制数据,并在文本视图中显示相应的值。下面是我开始编写的
<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>
如果我的计划根本不可能实现的话,我将非常感谢任何关于如何做到这一点的想法。对不起,我还不能发布图片。
提前谢谢
freeman您可以向微调器添加一个
OnItemClickListener
,从中获取TextView的数据
在微调器上,向您实现的侦听器调用setOnItemClickListener()。
在您的实现中,您将有一个onItemClick(AdapterView父项、视图、int位置、长id)
方法
在这里面,您可以调用适配器上的getItem(position)来选择项目,从而从那里获取数据,并通过setText()
希望有帮助,
JQCorreia感谢JQ的回复。我要先做家庭作业,看看如何做你的建议。对于如何获得与微调器中项目对应的值,仍然有点困惑。我的微调器只有项目1到F,而不是我想要显示的实际数据。我应该把实际数据放在哪里?