如何使列表视图的textview可单击 [英] how to make textview of the listview clickable
问题描述
我有一个包含一些Textviews
的自定义listview
.我将列表视图设置为adapter
,如下所示:
I have a customized listview
contains of some Textviews
. I set the list view to the adapter
as follows:
BestandTypAdapter bestandTypAdapter = new BestandTypAdapter(getActivity(), R.layout.bestand_type_liste, dataList);
li.setAdapter(bestandTypAdapter);
,如下面在bestand_type_liste布局的代码中所示,可单击TextView
and as shown below in the code of the bestand_type_liste layout the TextView is clickable
bestand_type_liste :
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/layout_depots_typ"
android:padding="5dip" >
<TableRow
android:paddingRight="10dip"
android:paddingLeft="10dip"
>
<TextView
android:id="@+id/BESTAND_TYP_NAME"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="0.50"
android:clickable="true"/> <<=================
在adapter
的getView()
方法中,我正在使用与名称TexView
关联的onClickListener
,以便单击该名称时,其位置将在logCat
上显示如下:
In the getView()
method of the adapter
i am using onClickListener
associated to the name TexView
so that when the name is clicked its position is displayed on the logCat
as follows:
holder.name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("", "position_ : " + pos);
}
});
问题是,当我单击listview
项目时,什么都没有出现,如何解决此问题
the problem is, when I click on the listview
item nothing appears, how to solve this issue
推荐答案
只需尝试为TextView添加此属性:
Just try to add this attribute for the TextView:
android:focusable="false"
这篇关于如何使列表视图的textview可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!