anurag shrivastava anurag shrivastava - 10 months ago 58
Android Question

Enable button in activity after the last item clicked

I am creating an app which has a

and a
. My problem is to enable this
after all the items in this
has been clicked. Elseway the
will be disabled.

How can I checked if all items has been clicked or not?

here is my adapter please take a look

public class InstallAdapter extends BaseAdapter {

private Activity activity;
private LayoutInflater inflater;
public List<InstallModel> galleryItems;
ProgressDialog dia;

public InstallAdapter(Activity activity,
ArrayList<InstallModel> galleryItems) {
this.activity = activity;
this.galleryItems = galleryItems;


public int getCount() {
// TODO Auto-generated method stub
Log.e("getCount :", galleryItems.size() + "");
return galleryItems.size();

public Object getItem(int position) {
// TODO Auto-generated method stub
Log.e("getItem :", galleryItems.get(position) + "");
return galleryItems.get(position);

public long getItemId(int position) {
// TODO Auto-generated method stub
Log.e("getItemId :", position + "");
return galleryItems.indexOf(getItem(position));

class ViewHolder {

Button Title;


public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub

final ViewHolder holder;
holder = new ViewHolder();
if (inflater == null)
inflater = (LayoutInflater) activity

convertView = inflater.inflate(R.layout.custom_list_result, null);

Log.e("AgetView", galleryItems.size() + "");

holder.Title = (Button) convertView.findViewById(;

Log.e("gallery postion", galleryItems.get(position) + "");

holder.Title.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

String url = galleryItems.get(position).getApp_url();
Intent i = new Intent(Intent.ACTION_VIEW);


/*if (position == getCount() - 1) {
} else {

return convertView;


Answer Source

An easy way could be adding a list of positions.

You can create an ArrayList of int. Everytime an user clicks on an item, you take this item position and you check if the ArrayList contains this index.

If it doesn't contain it, you add this int to the ArrayList.

After this you check the count of items in this ArrayList and if it's equals to the total count of items in your list, you are done.

Little code:

Add it inside list.setOnItemClickListener

ArrayList<int> myIndexes = new ArrayList<>()

//add onitemclick method with this body
if(myIndexes.length == myList.length){
  //enable button

Obiouvsly you have to replace names and implement methods, but this will work