vendredi 27 février 2015

setOnitemClicklistener not working for listview


Vote count:

0




I'm using this ListviewAnimations library for expanding list items as it is clicked. But Listener is not listening events as row is clicked. Below is related codes. Ontouch or onclick are also not working. No error is coming but onclick event are also not getting called. What could be the reason behind it?


Basically I want to change the height of the list view after row is selected so that layout looks properly. I have other controls as well below this Listview in my main layout.


Thanks in advance.


Code:



ListView Images_list_view;
mExpandableListItemAdapter = new MyExpandableListItemAdapter(this,no_of_images);
Images_list_view = (ListView)findViewById(R.id.Images);
AlphaInAnimationAdapter alphaInAnimationAdapter = new AlphaInAnimationAdapter(mExpandableListItemAdapter);
alphaInAnimationAdapter.setAbsListView(Images_list_view);
assert alphaInAnimationAdapter.getViewAnimator() != null;
alphaInAnimationAdapter.getViewAnimator().setInitialDelayMillis(500);
Images_list_view.setAdapter(alphaInAnimationAdapter);

Images_list_view.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub

Log.d("Clicked","clicked");
//changeheight();


}
});


My Adapter:



public class MyExpandableListItemAdapter extends ExpandableListItemAdapter<Integer> {

Context mContext;
int no;
protected MyExpandableListItemAdapter(Context context,int no_of_images) {
super(context,R.layout.activity_expandablelistitem_card, R.id.activity_expandablelistitem_card_title, R.id.activity_expandablelistitem_card_content);
this.mContext=context;
this.no=no_of_images;
for (int i = 0; i < no; i++) {
add(i);
}

// TODO Auto-generated constructor stub
}

@Override
@NonNull
public View getContentView(int position, @Nullable View convertView,
@NonNull ViewGroup arg2) {
// TODO Auto-generated method stub
ImageView imageView = (ImageView) convertView;
if (imageView == null) {
imageView = new ImageView(mContext);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
int imageResId = R.drawable.no_media;
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), imageResId);

imageView.setImageBitmap(bitmap);


return imageView;
}

@Override
@NonNull
public View getTitleView(int position, @Nullable View convertView,
@NonNull ViewGroup arg2) {
// TODO Auto-generated method stub
TextView tv = (TextView) convertView;
if (tv == null) {
tv = new TextView(mContext);
}

tv.setText(R.string.productimage);
return tv;
}


}


and xml file:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/card_background_white"
android:orientation="vertical"
android:padding="16dp"
tools:ignore="overdraw">

<FrameLayout
android:id="@+id/activity_expandablelistitem_card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<FrameLayout
android:id="@+id/activity_expandablelistitem_card_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp" />

</LinearLayout>


asked 1 min ago







setOnitemClicklistener not working for listview

Aucun commentaire:

Enregistrer un commentaire