【发布时间】:2015-10-23 00:15:38
【问题描述】:
我在 ListView 中使用了以下布局(意味着它对列表中的每个项目使用一次):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:id="@+id/stats"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="10 comments"
android:tag="10"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/stats"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="true"
android:onClick="increaseComments"
/>
</LinearLayout>
</LinearLayout>
如果用户点击ImageView,我想将TextView 的文本更改为“11 cmets”(递增)。给定下面ImageView的onClick方法,如何获取TextView的标签,然后用它来更改TextView的文本?
public void increaseComments(View view) {
// TODO
}
【问题讨论】:
-
ListView 本身在哪里?
-
在提出此类问题之前先进行 Google 搜索。您会在不到 1 分钟的时间内找到答案。
(int) imageView.getTag() -
@osayilgan 重新阅读问题。我在问如果我在我提供的 onClick 方法中单击
ImageView,如何获取TextView的标签... -
@AlexK 我没有必要提供 ListView (
<ListView> ... </ListView>) 布局。但是,我的问题中给出了列表 item 布局。 -
@user5477909 看我的回答。
标签: android android-layout android-intent android-activity android-xml