所以,我有一个头视图定义如下:问题与点击监听头在ListView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<TextView android:id="@+id/purchase_menu_header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="20sp"
android:text="@string/purchase_options_label"/>
</LinearLayout>
充气如下:
View header = ((Activity) context).getLayoutInflater().inflate(R.layout.purchase_menu_header, options, false); options.addHeaderView(header);
我对项目的点击监听器在选项列表视图中:
options.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Offer offer = (Offer) options.getItemAtPosition(position);
initiatePurchase(offer.getStoreProduct());
}
});
并为报头单击侦听器查看本身:
header.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
baseLayout.removeView(background);
baseLayout.removeView(overlay);
}
});
我的问题是,标题只注册点击文本部分的标题。所需的行为是让整个标题可点击。我尝试过使用setOnItemClickListener和getItemAtPosition(0)等解决方案,但是这会返回null。还试图用MATCH_PARENT扩展标题中的文本视图,但没有运气。
您是否尝试删除LinearLayout,即让您的布局文件只包含TextView?然后,您可以调整TextView的引力和/或填充以获得您想要的文本。 –
我也会在头上添加图片,所以我不认为这个解决方案会很好。 – Fullplate