I have a view pager where each page has a cardview with an image, some text, and a button. I need the button text of each page to change after being clicked.
So inside ViewPagerAdapter mapSize.setText() works only outside setOnClickListener(), while inside onClick it does not work.
This is my ViewPagerAdapter class
public class ViewPagerAdapter extends PagerAdapter {
private List<Model> models;
private LayoutInflater layoutInflater;
private Context context;
private Button mapSize;
private Integer size;
private static final String TAG = "ViewPagerAdapter";
public ViewPagerAdapter(Context context, List<Model> models, String playerName) {
this.models = models;
this.layoutInflater = layoutInflater;
this.context = context;
}
#Override
public int getCount() {
return models.size();
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object o) {
return view.equals(o);
}
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, final int position) {
layoutInflater = LayoutInflater.from(context);
View view = null;
ImageView imageView;
TextView title, desc;
imageView = view.findViewById(R.id.gameModeImage);
title = view.findViewById(R.id.title);
desc = view.findViewById(R.id.description);
imageView.setImageResource(models.get(position).getImage());
title.setText(models.get(position).getTitle());
desc.setText(models.get(position).getDescription());
mapSize = view.findViewById(R.id.mapSizeBtn);
mapSize.setText("hello2"); //here works
mapSize.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapSize.setText("hello"); //here does not work
}
});
container.addView(view, 0);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "This page was clicked: " + position);
if (position != 1)
Toast.makeText(context, "Coming Soon.", Toast.LENGTH_SHORT).show();
else {
Intent newGameActivity = new Intent(context, com.game.project.GameActivity.class);
newGameActivity.putExtra("size", size);
context.startActivity(newGameActivity);
}
}
});
return view;
}
#Override
public void destroyItem(#NonNull ViewGroup container, int position, #NonNull Object object) {
container.removeView((View)object);
}
}
You reassign your button each item a new item instantiates in your adapter.
You must reffer to your button in this way:
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, final int position) {
layoutInflater = LayoutInflater.from(context);
View view = null;
ImageView imageView;
TextView title, desc;
imageView = view.findViewById(R.id.gameModeImage);
title = view.findViewById(R.id.title);
desc = view.findViewById(R.id.description);
imageView.setImageResource(models.get(position).getImage());
title.setText(models.get(position).getTitle());
desc.setText(models.get(position).getDescription());
final Button mapSize = view.findViewById(R.id.mapSizeBtn);
mapSize.setText("hello2"); //here works
mapSize.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapSize.setText("hello"); //here does not work
}
});
container.addView(view, 0);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "This page was clicked: " + position);
if (position != 1)
Toast.makeText(context, "Coming Soon.", Toast.LENGTH_SHORT).show();
else {
Intent newGameActivity = new Intent(context, com.game.project.GameActivity.class);
newGameActivity.putExtra("size", size);
context.startActivity(newGameActivity);
}
}
});
return view;
}
All items in instantiate item should be declared final to work properly.
Related
I want to make selction menu for profiles using RecyclerView. I created it with RecyclerView. Now i am getting problem in onItemClickListener. I want to change background of CardView and Text Color on item select. at a time only one item can be selected. And on next button click it should redirect to activity according to selection.
This is my screen looks like:
public class SelectProfile extends AppCompatActivity {
private String[] mTextData;
private int[] mImgData;
RecyclerView recyclerView;
private ProfileAdapter profileAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_profile);
recyclerView = findViewById(R.id.recycleProfile);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this,2);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
profileAdapter = new ProfileAdapter();
recyclerView.setAdapter(profileAdapter);
int imgData[] = {R.drawable.ic_college_icon,R.drawable.ic_parent,R.drawable.ic_student,R.drawable.ic_teaching,
R.drawable.ic_non_teaching,R.drawable.ic_other};
final String textData[] = {"School/College","Parent","Student","Teaching Staff","Non-Teaching Staff","Other"};
profileAdapter.setData(imgData,textData);
}
private class ProfileAdapter extends RecyclerView.Adapter<ProfileAdapter.ProfileAdapterViewHolder>{
int index = -1;
#NonNull
#Override
public ProfileAdapterViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
Context context = parent.getContext();
int layoutIdForListItem = R.layout.profile_item;
LayoutInflater layoutInflater = LayoutInflater.from(context);
boolean shouldAttachToParent = false;
View view = layoutInflater.inflate(layoutIdForListItem,parent,shouldAttachToParent);
return new ProfileAdapterViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final ProfileAdapterViewHolder holder,final int position) {
int mImage = mImgData[position];
String mText = mTextData[position];
holder.img.setImageResource(mImage);
holder.txt.setText(mText);
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
index = position;
notifyDataSetChanged();
}
});
if (index == position){
holder.card.setBackground(getResources().getDrawable(R.drawable.bg_select_profile));
holder.txt.setTextColor(getResources().getColor(R.color.colorPrimary));
}else {
holder.card.setCardBackgroundColor(getResources().getColor(android.R.color.white));
holder.txt.setTextColor(getResources().getColor(R.color.gray));
}
}
#Override
public int getItemCount() {
if (null == mImgData) return 0;
return mImgData.length;
}
public class ProfileAdapterViewHolder extends RecyclerView.ViewHolder {
private final AppCompatImageView img;
private final TextView txt;
private final CardView card;
private ProfileAdapterViewHolder(#NonNull View itemView) {
super(itemView);
img = itemView.findViewById(R.id.img);
txt = itemView.findViewById(R.id.txt);
card = itemView.findViewById(R.id.card);
}
}
private void setData(int[] imgData,String[] txtData){
mImgData = imgData;
mTextData = txtData;
notifyDataSetChanged();
}
}
}
Your approach of using an Index variable is right, add getter and setter method for the index. But you can't set the onClickListener on the adapter. Instead, set the listener on the card view like this ->
holder.card.setOnItemClickListener(new ClickListener() {
#Override
public void onItemClick(int position, View v) {
index = position;
notifyDataSetChanged();
}
});
Add this method inside your adapter class ->
public int getSelectedIndex(){
return this.index; }
After that, from your Activity, inside your NEXT button's onClickListener do the following thing,
btnNext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(profileAdapter.getSelectedIndex() == 1)
//goto activity of your desire and so on
}
});
Use your card view as a parent layout for your recycler view item and apply on click listener to that card view in recycler view adapter.
holder.your_card_view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// get you recyclerview item position here
}
});
Add OnClickListner on holder root view , best place to write listener is in onCreateViewHolder , so replace your onCreateViewHolder with following
public ProfileAdapterViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
Context context = parent.getContext();
int layoutIdForListItem = R.layout.profile_item;
LayoutInflater layoutInflater = LayoutInflater.from(context);
boolean shouldAttachToParent = false;
View view = layoutInflater.inflate(layoutIdForListItem,parent,shouldAttachToParent);
ViewHolder viewHolder = new ViewHolder(view);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
postion=viewHolder.getAdapterPosition();
notifyDataSetChanged();
}
});
return viewHolder ;
}
change and adjust your adapter like as below:
private class ProfileAdapter extends RecyclerView.Adapter<ProfileAdapter.ProfileAdapterViewHolder>{
int index = -1;
#NonNull
#Override
public ProfileAdapterViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
Context context = parent.getContext();
int layoutIdForListItem = R.layout.profile_item;
LayoutInflater layoutInflater = LayoutInflater.from(context);
boolean shouldAttachToParent = false;
View view = layoutInflater.inflate(layoutIdForListItem,parent,shouldAttachToParent);
return new ProfileAdapterViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ProfileAdapterViewHolder holder, int position) {
int mImage = mImgData[position];
String mText = mTextData[position];
holder.img.setImageResource(mImage);
holder.txt.setText(mText);
if (index == position){
holder.card.setCardBackgroundColor(getResources().getColor(R.color.colorPrimary));
holder.txt.setTextColor(getResources().getColor(R.color.colorPrimary));
}else {
holder.card.setCardBackgroundColor(getResources().getColor(android.R.color.white));
holder.txt.setTextColor(getResources().getColor(R.color.gray));
}
}
#Override
public int getItemCount() {
if (null == mImgData) return 0;
return mImgData.length;
}
public class ProfileAdapterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private final AppCompatImageView img;
private final TextView txt;
private final CardView card;
private ProfileAdapterViewHolder(#NonNull View itemView) {
super(itemView);
img = itemView.findViewById(R.id.img);
txt = itemView.findViewById(R.id.txt);
card = itemView.findViewById(R.id.card);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
setIndex(getAdapterPosition());
notifyDataSetChanged();
}
}
private void setData(int[] imgData,String[] txtData){
mImgData = imgData;
mTextData = txtData;
notifyDataSetChanged();
}
public void setOnItemClickListener(ClickListener clickListener){
mClickListener = clickListener;
}
private void setIndex(int index){
this.index=index;
}
}
you may not need the ClickListener.
You can pass a listener object in the constructor which implements by fragment OR activity
/**
* item click interface of adapter
*/
public interface ProfileAdapterListener {
void onItemClick(int position, ProfileAdapterViewHolder holder)
}
This interface implements by Fragment OR Activity
/**
* On item clicked Implement Method from adapter listener.
*
* #param position
*/
#Override
public void onItemClick(int position, ProfileAdapterViewHolder holder) {
// Here you can call that method
}
Then you pass this listener in the constructor of the adapter.
private void buildRecyclerView() {
profileAdapter = new ProfileAdapter(this);
recyclerView.setAdapter(profileAdapter);
}
In the constructor, you can assign like this
private ProfileAdapterListener mProfileAdapterListener;
public OfferAdapter(ProfileAdapterListener mProfileAdapterListener) {
this.mProfileAdapterListener = mProfileAdapterListener
}
}
Now you can use this listener by setting click listener on any Viwe like this
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mProfileAdapterListener.onItemClick(position, holder);
}
});
It returns to call the method of onItemClick which implements this method. This is the safe and sound method to click on each item or any view in the item.
i have a GridView with a photos.
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_me, container, false);
TextView t = (TextView) view.findViewById(R.id.textName);
name = MySharedPreferences.getInstance(getActivity()).getName();
t.setText(name);
gridView = (GridView) view.findViewById(R.id.gridPhoto);
img = new ImageAdapter(getActivity(), path);
gridView.setAdapter(img);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//code
}
});
requestPath();
return view;
}
In requestPath() set the ImageAdapter with the url of the images.
In onItemClick I would like to get the image in the grid
This is ImageAdapter
public class ImageAdapter extends BaseAdapter {
private Context context;
private final LayoutInflater inflater;
private List<PathImage> path;
private String username = null;
public ImageAdapter(Context c, List<PathImage> path){
context = c;
this.path = path;
inflater = LayoutInflater.from(context);
}
public ImageAdapter(Context c, List<PathImage> path, String username){
context = c;
this.path = path;
inflater = LayoutInflater.from(context);
this.username = username;
}
#Override
public int getCount() {
return path.size();
}
#Override
public Object getItem(int position) {
return path.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ImageView imageView;
if (v == null) {
v = inflater.inflate(R.layout.gridview_item, parent, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
}
imageView = (ImageView) v.getTag(R.id.picture);
String url = "";
if(username == null) {
url = "http://example.com/image/" + MySharedPreferences.getInstance(context).getUsername() + "/";
}else{
url = "http://example.com/image/" + username + "/";
}
Glide.with(context).load(url + path.get(position).getPath()).into(imageView);
return v;
}
public void updatePath(List<PathImage> p){
path = p;
this.notifyDataSetChanged();
}
}
I would like to display the images in another fragment when I click on gridview.
How do I move an image from one fragment to another?
in ImageAdapter, implment a custome callback like below:
private ImageViewClickListener mImageViewClickListener;
public interface ImageViewClickListener {
void onImageClicked(int position);
}
public void setImageViewClickListener (ViewClickListener viewClickListener) {
mImageViewClickListener = viewClickListener;
}
Now, in your activity, implement ImageViewClickListener interface and call imageAdapter.setImageViewClickListener(this) and implement below code in getview:
imageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mImageViewClickListener.onImageClicked(position);
}
});
I'm a noob in android studios..and currently in learning stage.. i copied the code from #Nirav-Kalola in this community. I need help in passing a boolean value into the server whenever left or right is swiped in android swipe cards.
Below is the code:
public class MainActivity extends AppCompatActivity implements FlingCardListener.ActionDownInterface{
public static MyAppAdapter myAppAdapter;
public static ViewHolder viewHolder;
private ArrayList<Data> al;
private SwipeFlingAdapterView flingContainer;
public static void removeBackground() {
viewHolder.background.setVisibility(View.GONE);
myAppAdapter.notifyDataSetChanged();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
al = new ArrayList<>();
al.add(new Data("http://www.drodd.com/images15/1-7.jpg", "Hello Anuj"));
al.add(new Data("http://www.drodd.com/images15/2-23.jpg", "Welcome to the final problem"));
al.add(new Data("http://www.drodd.com/images15/3-12.jpg","\t here goes the name of the person "));
al.add(new Data("http://www.drodd.com/images15/4-7.jpg", " buhahahahahahahaha"));
al.add(new Data("http://www.drodd.com/images15/5-18.jpg", "miss me?"));
myAppAdapter = new MyAppAdapter(al, MainActivity.this);
flingContainer.setAdapter(myAppAdapter);
flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
#Override
public void removeFirstObjectInAdapter() {
}
#Override
public void onLeftCardExit(Object dataObject) {
al.remove(0);
myAppAdapter.notifyDataSetChanged();
//Do something on the left!
//You also have access to the original object.
//If you want to use it just cast it (String) dataObject
}
#Override
public void onRightCardExit(Object dataObject) {
al.remove(0);
myAppAdapter.notifyDataSetChanged();
}
#Override
public void onAdapterAboutToEmpty(int itemsInAdapter) {
}
#Override
public void onScroll(float scrollProgressPercent) {
View view = flingContainer.getSelectedView();
view.findViewById(R.id.background).setAlpha(0);
view.findViewById(R.id.item_swipe_right_indicator).setAlpha(scrollProgressPercent < 0 ? -scrollProgressPercent : 0);
view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0);
}
});
// Optionally add an OnItemClickListener
flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() {
#Override
public void onItemClicked(int itemPosition, Object dataObject) {
View view = flingContainer.getSelectedView();
view.findViewById(R.id.background).setAlpha(0);
myAppAdapter.notifyDataSetChanged();
}
});
}
#Override
public void onActionDownPerform() {
Log.e("action", "bingo");
}
public static class ViewHolder {
public static FrameLayout background;
public TextView DataText;
public ImageView cardImage;
}
public class MyAppAdapter extends BaseAdapter {
public List<Data> parkingList;
public Context context;
private MyAppAdapter(List<Data> apps, Context context) {
this.parkingList = apps;
this.context = context;
}
#Override
public int getCount() {
return parkingList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = getLayoutInflater();
rowView = inflater.inflate(R.layout.item, parent, false);
// configure view holder
viewHolder = new ViewHolder();
viewHolder.DataText = (TextView) rowView.findViewById(R.id.bookText);
viewHolder.background = (FrameLayout) rowView.findViewById(R.id.background);
viewHolder.cardImage = (ImageView) rowView.findViewById(R.id.cardImage);
rowView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.DataText.setText(parkingList.get(position).getDescription() + "");
Glide.with(MainActivity.this).load(parkingList.get(position).getImagePath()).into(viewHolder.cardImage);
return rowView;
}
}
}
Just do your network call in these two methods
#Override
public void onLeftCardExit(Object dataObject) {
al.remove(0);
myAppAdapter.notifyDataSetChanged();
//Do something on the left!
//You also have access to the original object.
//If you want to use it just cast it (String) dataObject
}
#Override
public void onRightCardExit(Object dataObject) {
al.remove(0);
myAppAdapter.notifyDataSetChanged();
}
I am trying to use the material dialogs library Material Dialog and i can't get the callback to work for the custom adapter.
The items are displayed perfectly but on click of the items i don't get any callback.
Base Adapter
public class EcardBaseAdapter extends BaseAdapter implements View.OnClickListener {
private LayoutInflater mInflater;
private List<? super Greeting> items;
private Context context;
private final int width;
private final int height;
public EcardBaseAdapter(List<Greeting> items, Context context) {
this.context = context;
mInflater = LayoutInflater.from(context);
this.items = items;
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
this.width = metrics.widthPixels;
this.height = metrics.heightPixels;
}
#Override
public int getCount() {
return items.size();
}
#Override
public Object getItem(int i) {
return items.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
ViewHolder holder;
if (convertView == null) {
view = mInflater.inflate(R.layout.custom_item, parent, false);
holder = new ViewHolder();
holder.avatar = (ImageView) view.findViewById(R.id.image_path);
holder.name = (TextView) view.findViewById(R.id.custom_event_name);
view.setTag(holder);
} else {
view = convertView;
holder = (ViewHolder) view.getTag();
}
if (items.get(position) instanceof ECard) {
ECard eCard = (ECard) items.get(position);
Log.i("test", eCard.getImage() + " " + eCard.getSubject());
if (eCard.getImage() != null) {
Glide.with(context)
.load(eCard.getImage())
.fitCenter()
.override(width, height / 2)
.into(holder.avatar);
//holder.avatar.setImageURI(Uri.parse(eCard.getImage()));
}
holder.name.setTextColor(ContextCompat.getColor(context, R.color.darkGrey));
holder.name.setText(eCard.getSubject());
}
return view;
}
#Override
public void onClick(View view) {
Log.i("click", "itemclick");
}
private class ViewHolder {
public ImageView avatar;
public TextView name;
}
}
Code in the activity which uses the adapter
new MaterialDialog.Builder(birthday_details.this)
.title("Ecard")
.adapter(adapter,
new MaterialDialog.ListCallback() {
#Override
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
Toast.makeText(birthday_details.this, "Clicked item " + which, Toast.LENGTH_SHORT).show();
}
})
.show();
I did not understandd all your code, but I seems you never call
view.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("click", "itemclick");
}
};
or in your case
view.setOnClickListener(this);
I wanna to implement multiple button in my ListView items. But the problem is that i couldn't handle click event when button is clicked, i mean they are Play button and Image button like this
Here is my Adapter:
public class ArtistsAdapter extends BaseAdapter implements SectionIndexer {
private HashMap<String, Integer> alphaIndexer;
private String[] sections;
private LayoutInflater inflater;
private int resId;
private Context context;
private ArrayList<Artist> artistList;
public ArtistsAdapter(Context context, int resId, ArrayList<Artist> artistList) {
this.resId = resId;
this.context = context;
this.artistList = artistList;
this.inflater = LayoutInflater.from(context);
}
#Override
public Object[] getSections() {
return sections;
}
#Override
public int getPositionForSection(int section) {
return alphaIndexer.get(sections[section]);
}
#Override
public int getSectionForPosition(int position) {
return 1;
}
private static class ViewHolder {
ImageView artistImgItem;
ImageButton artistPlayItem;
TextView artistNameItem;
TextView artistAgeItem;
LinearLayout artistItem;
}
#Override
public int getCount() {
return artistList.size();
}
#Override
public Object getItem(int position) {
return artistList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
Artist artist = (Artist) getItem(position);
ViewHolder viewHolder;
if (convertView == null) {
convertView = this.inflater.inflate(resId, parent, false);
viewHolder = new ViewHolder();
viewHolder.artistImgItem = (ImageView) convertView.findViewById(R.id.artistImg);
viewHolder.artistPlayItem = (ImageButton) convertView.findViewById(R.id.artistPlay);
viewHolder.artistNameItem = (TextView) convertView.findViewById(R.id.artistName);
viewHolder.artistAgeItem = (TextView) convertView.findViewById(R.id.artistAge);
viewHolder.artistItem = (LinearLayout) convertView.findViewById(R.id.artistItem);
convertView.setTag(viewHolder);
} else viewHolder = (ViewHolder) convertView.getTag();
viewHolder.artistNameItem.setText(artist.getName());
viewHolder.artistPlayItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("aaaaa", position+"ssss");
Toast.makeText(context, "Music playin " + position+1 +"", Toast.LENGTH_SHORT).show();
}
});
viewHolder.artistItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((ArtistsActivity) context).showArtistView();
}
});
viewHolder.artistImgItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((ArtistsActivity) context).showArtistView();
}
});
return convertView;
}
}
And my activity looks like that
public class ArtistsActivity extends Activity {
private IndexableListView artistListUI;
private ImageView maleArtist, femaleArtist, groupArtist, artistImg;
private ArtistsAdapter artistsAdapter;
private ArrayList<Artist> maleArtistList, femaleArtistList, groupArtistList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.artist_list);
artistListUI = (IndexableListView) findViewById(R.id.artistListView);
maleArtist = (ImageView) findViewById(R.id.maleArtist);
femaleArtist = (ImageView) findViewById(R.id.femaleArtist);
groupArtist = (ImageView) findViewById(R.id.groupArtist);
artistImg = (ImageView) findViewById(R.id.artistImg);
artistListUI.setFastScrollEnabled(true);
artistsAdapter = new ArtistsAdapter(ArtistsActivity.this, R.layout.artist_item, artistList);
artistListUI.setAdapter(artistsAdapter);
public void showArtistView() {
startActivity(new Intent(ArtistsActivity.this, AlbumsActivity.class));
}
}
you have to set clickable property of listview to false
because of entire listview click is fire
This is resolved in the adapter. Look at this example:
https://github.com/m-alcu/SkoltiAlert/blob/master/src/com/alcubier/skoltialert/tracks/TrackAdapter.java
In the bindView or getView method you have to define your clickhandler linked to your view:
holder.hLayout.setOnClickListener(new MentionClickhandler());
And do sour stuff in this function:
public class MentionClickhandler implements View.OnClickListener
{
public void onClick( View view ){
Track trackTag = new Track();
trackTag = (Track) view.getTag();
Log.i(TAG, "item: "+trackTag.getSearchTrack());
Bundle bundle = new Bundle();
bundle.putInt("idTrack", trackTag.getIdTrack());
bundle.putString("searchTrack", trackTag.getSearchTrack());
bundle.putInt("topTrack", trackTag.getTopTrack());
bundle.putLong("lastId", trackTag.getLastId());
bundle.putInt("count", trackTag.getCount());
bundle.putString("type", "LastMentions");
Intent i = new Intent(context, GDMentionsList.class);
i.putExtras(bundle);
context.startActivity(i);
}
}
Hope it helps...