RelativeLayout onClick attribute not working



I am showing a List in a ListView through a custom adapter SongsListAdapter.java with custom itemview music_item.xml and there is a method i want to call in my Activity Class MainActivity.java so i cannot use setOnClickListener method

what i did is i added an attribute to music_item.xml onClickto call method in MainActivity.java

but this is not working, by clicking the list item it is not invoking the method from Activity class



SongsListAdapter.java



public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.music_item, null);
this.mView = view;
holder.title = (TextView) view.findViewById(R.id.songName);
holder.descr = (TextView) view.findViewById(R.id.songArtists);
holder.dp = (ImageView) view.findViewById(R.id.albumIcon);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.title.setText(SongsListItemslist.get(position).getDisplayName());
holder.descr.setText(SongsListItemslist.get(position).getArtist());
holder.dp.setImageBitmap(SongsListItemslist.get(position).getBitmap());
// Listen for ListView Item Click
view.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
}
});
return view;
}


MainActivity.java



public void songPicked(View view) {
Log.v("clicked", "clicked");
musicSrv.setSong(Integer.parseInt(view.getTag().toString()));
musicSrv.playSong();
}


Music_item.xml



<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/card"
android:clickable="true"
android:onClick="songPicked" >

<ImageView
android:id="@+id/albumIcon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/abc_ab_bottom_solid_dark_holo" />
</RelativeLayout>


And i couldn't able to see clicked in my Logs..


No comments:

Post a Comment