I’m using android-amazing-listview in my android application, and I want to show some details when user clicks on an item in listview. But the thing is when I set click listener on the item it also listens the header section as an item. Here is my code below, and you can also take a look to the XML file.
@Override
public View getAmazingView(int position, View convertView, ViewGroup parent) {
View res = convertView;
if (res == null) res = getLayoutInflater().inflate(R.layout.menu_item, null);
TextView lName = (TextView) res.findViewById(R.id.lName);
TextView lYear = (TextView) res.findViewById(R.id.lYear);
LinearLayout item = (LinearLayout) res.findViewById(R.id.item);
Items composer = getItem(position);
lName.setText(composer.title);
lYear.setText(composer.summary);
// here I set my click listener just for the item
item.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "OnClick event !!!", Toast.LENGTH_LONG).show();
}
});
return res;
}
And here is the XML for items.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/menu_item" >
<include
layout="@layout/menu_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/item"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:padding="6dp"
android:clickable="true" >
<TextView
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/lName" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/lYear" />
</LinearLayout>
Any help will be appreciated.
I finally figured out the reason why the header also is getting clicked when I click the item.
The Reason is I use AmazingListView. So according to this library header and item are the same item of the list. When the header goes to top of the list view, copy of the header is getting drawn to pin it up to head of the list.