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();
}
Related
I have a ListView with a gridview for each item:
So when I press the add button I need to add a new item to the gridView(scenesGridViewAdapter) adapter, but when I press the add button always is added to the last gridview.
public class ScenesAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<SceneObject> sceneObjects;
private ArrayList<ScenesGridViewAdapter> scenesGridViewAdapters;
private ScenesGridViewAdapter scenesGridViewAdapter;
public ScenesAdapter(Activity activity, ArrayList<SceneObject> sceneObjects) {
this.activity = activity;
this.sceneObjects = sceneObjects;
this.scenesGridViewAdapters = new ArrayList<>();
}
#Override
public int getCount() {
return this.sceneObjects.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_scenes_item, null);
viewHolder = new ViewHolder();
viewHolder.tvStepIndex = (TextView) convertView.findViewById(R.id.tv_scene_index);
viewHolder.bmb1 = (BoomMenuButton) convertView.findViewById(R.id.bmb_open_item_menu);
viewHolder.scenesGridView = (ScenesGridView)convertView.findViewById(R.id.gv_scene_items) ;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
int index = position + 1;
viewHolder.tvStepIndex.setText("" + index);
scenesGridViewAdapter = new
ScenesGridViewAdapter(this.activity, sceneObjects.get(position).getScenes());
viewHolder.scenesGridView.setAdapter(scenesGridViewAdapter);
viewHolder.bmb1.clearBuilders();
viewHolder.bmb1.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilder("Añadir acción"));
viewHolder.bmb1.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilder("Eliminar paso"));
viewHolder.bmb1.setOnBoomListener(new OnBoomListener() {
#Override
public void onClicked(int index, BoomButton boomButton) {
switch (index){
case 0:
scenesGridViewAdapter.addNew("hello");
notifyDataSetChanged();
break;
case 1:
sceneObjects.remove(position);
notifyDataSetChanged();
break;
}
}
#Override
public void onBackgroundClick() {
}
#Override
public void onBoomWillHide() {
}
#Override
public void onBoomDidHide() {
}
#Override
public void onBoomWillShow() {
}
#Override
public void onBoomDidShow() {
}
});
return convertView;
}
class ViewHolder {
TextView tvStepIndex;
ScenesGridView scenesGridView;
BoomMenuButton bmb1;
}
public void addNewScene(SceneObject sceneObject){
sceneObjects.add(sceneObject);
this.notifyDataSetChanged();
}
}
Can you please help me to add and item to the gridview position?
Thank you.
Is there a way to set onClickListener on Imageview(Listview) inside activity ?
I'v created this , and it works just fine in my adapter, But it's not working in my activity :
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
playPause=(ImageView)view.findViewById(R.id.playPause);
Product m = productList.get(position);
playPause.setImageResource(m.getPlayPauseId());
playPause.setTag(position);
playPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int pos = (Integer) v.getTag();
Product m =productList.get(pos);
if (paused) {
m.setPlayPauseId(R.drawable.ic_pause);
paused=false;
}else {
m.setPlayPauseId(R.drawable.ic_play);
paused = true;
}
adapter.notifyDataSetChanged();
}
});
}
And this is my Product class :
public class Product implements Serializable {
private int PlayPauseId;
#SerializedName("pid")
public int pid;
#SerializedName("name")
public String name;
#SerializedName("qty")
public int qty;
#SerializedName("price")
public String description;
#SerializedName("image_url")
public String image_url;
#SerializedName("date")
public String date;
public int getPlayPauseId() {
return PlayPauseId;
}
public void setPlayPauseId(int playPauseId) {
PlayPauseId = playPauseId;
}
}
Adapter Class (Fundapter library) :
public class FunDapter<T> extends BaseAdapter implements Filterable {
protected List<T> mDataItems;
protected List<T> mOrigDataItems;
protected LongExtractor<T> idExtractor;
protected final Context mContext;
private final int mLayoutResource;
private final BindDictionary<T> mBindDictionary;
private int oddColorRes;
private int evenColorRes;
private FunDapterFilter<T> funDapterFilter;
private Filter mFilter;
public FunDapter(Context context, List<T> dataItems, int layoutResource,
BindDictionary<T> dictionary) {
this(context, dataItems, layoutResource, null, dictionary);
}
public FunDapter(Context context, List<T> dataItems, int layoutResource,
LongExtractor<T> idExtractor, BindDictionary<T> dictionary) {
this.mContext = context;
this.mDataItems = dataItems;
this.mOrigDataItems = dataItems;
this.mLayoutResource = layoutResource;
this.idExtractor = idExtractor;
this.mBindDictionary = dictionary;
}
public void updateData(List<T> dataItems) {
this.mDataItems = dataItems;
this.mOrigDataItems = dataItems;
notifyDataSetChanged();
}
#Override
public int getCount() {
if (mDataItems == null || mBindDictionary == null) return 0;
return mDataItems.size();
}
#Override
public T getItem(int position) {
return mDataItems.get(position);
}
#Override
public boolean hasStableIds() {
if(idExtractor == null) return super.hasStableIds();
else return true;
}
#Override
public long getItemId(int position) {
if(idExtractor == null) return position;
else return idExtractor.getLongValue(getItem(position), position);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
final GenericViewHolder holder;
if (null == v) {
LayoutInflater vi =
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(mLayoutResource, null);
holder = new GenericViewHolder();
holder.root = v;
FunDapterUtils.initViews(v, holder, mBindDictionary);
v.setTag(holder);
} else {
holder = (GenericViewHolder) v.getTag();
}
final T item = getItem(position);
showData(item, holder, position);
return v;
}
you can do it with two ways:
Make an interface something like this
public interface ImageClick {
public imageButtonOnClick(View view, int position)
}
implement it in your activity, and in your adapter getView, set imageOnClickListener, and call this interface method inside that onClick, pass your position and view in it, so you can use position etc in your activity callback.
Second is to just make a method in your activity like in interface
public imageButtonOnClick(View view, int position)
in your adapter onClick method on imageView, call it something like
((YourActivity)context).imageButtonOnClick(params1, param2);
Custom your ArrayAdapter and set action in method getView
See this page
ListView with Add and Delete Buttons in each Row in android
For getting click the image in the list view in the activity itself you have to callback
Create an interface
public interface OnButtonClickListener {
public void onButtonClick(int position,View view);
}
in your actvity class implement OnButtonClickListener
you get a interface methood
#Override
public void onButtonClick(final int position, View view) {
int id = view.getId();
switch (id) {
case R.id.YOURIMAGEVIEWID:
//implent your process...
}
}
Create constructor in adapter calss
Context context;
OnButtonClickListener callback
public AdapterClass(Context context OnButtonClickListener buttonClickListener) {
this.context = context;
callback = buttonClickListener;
}
image click in adapter class
holder.imageView..setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
callback.onButtonClick(position, v);
}
});
in your actvity class
AdapterClass Adapter = new AdapterClass(youractivity.this, youractivity.this);
Add this class for callback
public class ListCustomClickEvents implements OnClickListener,View.OnTouchListener {
private int position;
private OnCustomClickListener callback;
// Pass in the callback (this'll be the activity) and the row position
public ListCustomClickEvents(OnCustomClickListener callback, int pos) {
position = pos;
this.callback = callback;
}
#Override
public void onClick(View v) {
callback.OnCustomClick(v, position);
}
}
i am having a small problem with memory when i tried to used nested RecyclerView and it crashed because it was not recycling views and as a result it run out of memory. So i have to go with another solution. I have created my own layout which accepts a Adapter like this:
public class CustomTileLayout extends LinearLayout {
private Adapter mAdapter;
private Observer mObserver = new Observer();
public CustomTileLayout(Context context) {
super(context);
}
public CustomTileLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Adapter getAdapter() {
return mAdapter;
}
public void setAdapter(Adapter mAdapter) {
if (mAdapter != null)
mAdapter.unregisterDataSetObserver(mObserver);
this.mAdapter = mAdapter;
mAdapter.registerDataSetObserver(mObserver);
mObserver.onChanged();
}
private class Observer extends DataSetObserver {
#Override
public void onChanged() {
final List<View> oldViews = new ArrayList<View>(getChildCount());
for (int i = 0; i < getChildCount(); i++)
oldViews.add(getChildAt(i));
final Iterator<View> iter = oldViews.iterator();
removeAllViews();
for (int i = 0; i < mAdapter.getCount(); i++) {
View convertView = iter.hasNext() ? iter.next() : null;
View newView = mAdapter.getView(i, convertView, CustomTileLayout.this);
addView(newView);
}
super.onChanged();
}
#Override
public void onInvalidated() {
removeAllViews();
super.onInvalidated();
}
}
}
and while i use it like:
tileHolder = (GameCategoriesTileViewHolder) holder;
section = (Section) items.get(position);
tileHolder.customTileLayout.setAdapter(new GameTileAdapter(section.getGames(), context, R.layout.row_small_tile));
Everything works fine so far but there is a problem. The problem is that it looks like this:
while i want it each row to have 3 tiles like this:
If i specify the child layout to be like the result since it is the same item it only populates the 1st tile and the next 2 are blank.
My adapter:
public class GameTileAdapter implements ListAdapter {
private List<Game> games;
private Context context;
private int resLayout = R.layout.row_small_tile;
private boolean isFavoriteFragmentView = false;
private PopupMenu popupMenu;
public GameTileAdapter(List<Game> games, Context context, int resLayout) {
this.games = games;
this.context = context;
this.resLayout = resLayout;
}
#Override
public void registerDataSetObserver(DataSetObserver observer) {
}
#Override
public void unregisterDataSetObserver(DataSetObserver observer) {
}
#Override
public int getCount() {
return games.size();
}
#Override
public Object getItem(int position) {
return games.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
SingleItemViewHolder holder;
if (itemView == null){
LayoutInflater vi;
vi = LayoutInflater.from(context);
itemView = vi.inflate(resLayout, parent, false);
holder = new SingleItemViewHolder(itemView);
holder.game_name.setText(games.get(position).getName());
if (games.get(position).getImageUri().isEmpty()){
holder.game_imageuri.setImageResource(R.drawable.ic_image_placeholder);
}else {
Picasso.with(context).load(games.get(position).getImageUri()).into(holder.game_imageuri);
}
holder.itemLineColor.setBackgroundColor(GameManager.getmInstance(context).getGameColor(games.get(position)));
}else {
holder = (SingleItemViewHolder)itemView.getTag();
}
return itemView;
}
#Override
public boolean areAllItemsEnabled() {
return true;
}
#Override
public boolean isEnabled(int position) {
return true;
}
private static class SingleItemViewHolder{
CardView cv;
TextView game_name;
TextView game_is_new;
TextView game_jackpot;
ImageView game_imageuri;
View itemLineColor;
Button favorite_button;
Button menu_button;
SingleItemViewHolder(View itemView) {
cv = (CardView)itemView.findViewById(R.id.root_layout);
game_name = (TextView)itemView.findViewById(R.id.game_name_text);
game_is_new = (TextView)itemView.findViewById(R.id.game_new_ribbon);
game_jackpot = (TextView)itemView.findViewById(R.id.game_jackpot_ribbon);
game_imageuri = (ImageView)itemView.findViewById(R.id.game_imageuri);
itemLineColor = (View)itemView.findViewById(R.id.single_line_color);
favorite_button = (Button)itemView.findViewById(R.id.favButton);
menu_button = (Button)itemView.findViewById(R.id.menu_button_tile);
}
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public int getViewTypeCount() {
return games.size();
}
#Override
public boolean isEmpty() {
return games.isEmpty();
}
}
Any ideas of how i can get the result?
You can use a layout for inner RecyclerView and add inflate a layout dynamically.
#Override
public void onBindViewHolder(RecentErrorsAdapter.ViewHolder holder, int position) {
try {
ArrayList<String> innerArrayList = new ArrayList<String>();
innerArrayList = mDataset.get(position).getInnerDataList();
for (int i = 0; i < innerArrayList.size(); i++) {
LayoutInflater inflater = null;
inflater = (LayoutInflater) context.getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mLinearView = inflater.inflate(R.layout.your_layout, null);
/**
* getting id of row.xml
*/
TextView textName = (TextView) mLinearView
.findViewById(R.id.txt_name);
textName.setText(innerArrayList.get(i));
holder.lstProgramName.addView(mLinearView);
}
} catch (Exception e) {
e.printStackTrace();
}
}
I have a gridview with items that I can increase or diminish its values, what is happening is when I change the value of the item and scroll down the screen
and scroll back the change that I made is gone, and if I scroll down and up a couple times I can see the change that I made again, what am I missing here?
public class SearchItemViewAdapter extends RealmSearchAdapter<Itens, SearchItemViewAdapter.ViewHolder> implements RealmChangeListener {
public SparseBooleanArray mSparseBooleanArray;
public SearchItemViewAdapter(Activity context, Realm realm, String filterColumnName) {
super(context, realm, filterColumnName);
mSparseBooleanArray = new SparseBooleanArray();
}
#Override
public void onChange() {
notifyDataSetChanged();
}
public RealmList<Itens> getCheckedItems() {
RealmList<Itens> mTempArry = new RealmList<>();
for (int i = 0; i < realmResults.size(); i++) {
if (mSparseBooleanArray.get(i)) {
mTempArry.add(realmResults.get(i));
}
}
return mTempArry;
}
public class ViewHolder extends RealmSearchViewHolder {
public SearchItemView itemView;
public ViewHolder(FrameLayout container, TextView footerTextView) {
super(container, footerTextView);
}
public ViewHolder(SearchItemView itemView) {
super(itemView);
this.itemView = itemView;
}
}
#Override
public ViewHolder onCreateRealmViewHolder(ViewGroup viewGroup, int viewType) {
ViewHolder vh = new ViewHolder(new SearchItemView(viewGroup.getContext()));
return vh;
}
#Override
public void onBindRealmViewHolder(ViewHolder viewHolder, int position) {
final Itens item = realmResults.get(position);
viewHolder.itemView.bind(item);
viewHolder.itemView.check.setTag(position);
viewHolder.itemView.check.setChecked(mSparseBooleanArray.get(position));
viewHolder.itemView.check.setOnCheckedChangeListener(mCheckedChangeListener);
}
CompoundButton.OnCheckedChangeListener mCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mSparseBooleanArray.put((Integer) buttonView.getTag(), isChecked);
}
};
#Override
public ViewHolder onCreateFooterViewHolder(ViewGroup viewGroup) {
View v = inflater.inflate(R.layout.footer_view, viewGroup, false);
return new ViewHolder(
(FrameLayout) v,
(TextView) v.findViewById(R.id.footer_text_view));
}
#Override
public void onBindFooterViewHolder(ViewHolder holder, int position) {
super.onBindFooterViewHolder(holder, position);
holder.itemView.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
}
}
);
}
}
SearchItemView
public class SearchItemView extends RelativeLayout {
#Bind(R.id.codigo)
TextView codigo;
#Bind(R.id.nomeproduto)
TextView nome;
#Bind(R.id.preco)
TextView preco;
#Bind(R.id.valor)
TextView itemq;
#Bind(R.id.more)
ImageView more;
#Bind(R.id.less)
ImageView less;
#Bind(R.id.check)
CheckBox check;
final int nStart = 0;
final int nEnd = 10000000;
public SearchItemView(Context context) {
super(context);
init(context);
}
private void init(Context context) {
inflate(context, R.layout.add_itens_adapter, this);
ButterKnife.bind(this);
}
public void bind(Itens item) {
nome.setText(item.getNome());
codigo.setText(item.getCodigo());
preco.setText(item.getPreco());
more.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String getString = String.valueOf(itemq.getText());
int curent = Integer.parseInt(getString);
if (v == more) {
if (curent < nEnd) {
curent++;
itemq.setText(String.valueOf(curent));
}
}
}
});
less.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String getString = String.valueOf(itemq.getText());
int curent = Integer.parseInt(getString);
if (v == less) {
if (curent > nStart) {
curent--;
itemq.setText(String.valueOf(curent));
}
}
}
});
}
}
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...