【发布时间】:2017-11-28 03:44:08
【问题描述】:
我正在尝试获取对我的微调器(布局)的选定项目的视图的引用。我正在使用带有自定义布局的SimpleCursorAdapter。这是我的适配器的一些代码:
adapter = new SimpleCursorAdapter(getActivity(),
R.layout.task_row, null,
new String[] { DbHandler.TASK_TITLE, DbHandler.TASK_NOTE},
new int[] { R.id.title, R.id.note}, 0);
spinner.setAdapter(adapter);
这里是 task_row.xml:
<RelativeLayout>
<ImageView
android:id="@+id/avatar"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/avatar" />
<TextView
android:id="@+id/title"
android:textStyle="bold"
android:layout_toRightOf="@id/avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/note"
android:layout_toRightOf="@id/avatar"
android:layout_below="@id/title"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
我试图获取对RelativeLayout 的引用的原因是,例如,我可以访问TextView 孩子的text 属性。我知道有一个名为getItemSelected() 的方法可以在我的Spinner 上使用,但是这个方法返回一个对象,我不知道它是什么。
【问题讨论】:
-
您好,我认为您有一个自定义适配器,并且您想从该适配器获取微调器值
-
嗨。我正在使用 SimpleCursorAdapter (developer.android.com/reference/android/widget/…)。此处微调器的“值”没有意义,因为显示的是我的自定义布局,其中包含一个 ImageView 和两个 TextView。我想要的是所选项目的 TextView 子项之一的文本属性。如果可以从适配器中获取它,那么当然可以。
-
您是否尝试过从视图中获取价值?
-
这就是我想要做的。但我需要一个参考。
-
好的,我看过了
标签: java android xml android-spinner android-adapter