Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8416865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:53:17+00:00 2026-06-10T01:53:17+00:00

I can’t seem to figure out how to do this, basically I have a

  • 0

I can’t seem to figure out how to do this, basically I have a list view with a bunch of buttons that each have their own individual values, this all works great until I want to hide certain buttons it all goes to pot.

This listview has it’s own custom adaptor the code for this is:

Imports removed for space but they exist.

public class FriendsArrayAdapter extends ArrayAdapter<Friend> 
{
    public FriendsArrayAdapter
    (Activity context, int resourceId, ArrayList<Friend> friends) 
{
    super(context, resourceId, friends);
    this.context = context;
    this.friends = friends;
    this.resourceId = resourceId;



}



@Override
public View getView(int position, View convertView, ViewGroup parent) 
{
    View rowView = convertView;
    if (rowView == null) 
    {
        LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = vi.inflate(resourceId, null);
    }



    alert = new AlertDialog.Builder(context);
    alert.setTitle("Hanged! Online Play");
    alert.setMessage("Enter a word for your opponent to guess. Alphabetical characters only and maximum of 25 characters long.");
    final EditText input = new EditText(context);
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() 
    {
    public void onClick(DialogInterface dialog, int whichButton) 
    {
       wordToGuess = input.getText().toString();
       SubmitWord submitTask = new SubmitWord();
       submitTask.execute(new String[] { "http://www.hanged.comli.com/main.php" });
       Log.i("postData", wordToGuess);
     }
    });

   alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
    {
      public void onClick(DialogInterface dialog, int whichButton) 
      {
          Intent intent = new Intent(context, NetPlay.class);
          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);       
          context.startActivity(intent);
      }
    });

    final Friend f = friends.get(position);
    TextView rowTxt = (TextView) rowView.findViewById(R.id.rowtext_top);
    rowTxt.setText(f.name+"       ");




    Button battleBtn = (Button) rowView.findViewById(R.id.battleBtn);
    battleBtn.setText(f.id+" Accept Challenge");
    battleBtn.setOnClickListener(new OnClickListener() 
    {
           @Override
           public void onClick(View v) 
           {
               rivalid = f.id;
               AcceptChallenge task2 = new AcceptChallenge();
               task2.execute(new String[] { "http://www.hanged.comli.com/get-currentgame.php" });
           }
    });

    Button newgameBtn = (Button) rowView.findViewById(R.id.newgameBtn);
    newgameBtn.setText(f.id+" Start new game.");

    newgameBtn.setOnClickListener(new OnClickListener() 
    {
           @Override
           public void onClick(View v) 
           {
               rivalid = f.id;
               alert.show();  
           }   
    });



        for (int i = 0;i<NetPlay.victimArray.length-1;i++)
        {
            Log.i("VICTIM ARRAY DATA ", NetPlay.victimArray[i]);

            if (NetPlay.victimArray[i].equals(NetPlay.myId))
            {
                ingame = false;
            }
            else
            {
                ingame = true;
            }
        }

        for (int i = 0;i<NetPlay.rivalArray.length-1;i++)
        {
            Log.i("RIVAL ARRAY DATA ", NetPlay.rivalArray[i]);

            if (NetPlay.rivalArray[i].equals(NetPlay.myId))
            {
                battle = true;
            }
            else
            {
                battle = false;
            }

        }

        if (battle.equals(false))
        {
            battleBtn.setVisibility(View.INVISIBLE);
        }
        if (ingame.equals(false))
        {
            newgameBtn.setVisibility(View.INVISIBLE);
        }


    return rowView;
}

Whenever I manage to hide these buttons, they all get hidden rather than just the buttons that should be hidden if that makes sense?
This view relies on some data from an asynchtask if that information helps any.

Would really appreciate some help with this, completely confusing me as to how I could possibly do it.

This is where the listview is called, in my Main activity.

listView = (ListView) findViewById(R.id.friendsview);
friendsArrayAdapter = new FriendsArrayAdapter(this, R.layout.rowlayout, friends);
listView.setAdapter(friendsArrayAdapter);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:53:19+00:00Added an answer on June 10, 2026 at 1:53 am

    The problem is with this block of code:

    if (battle.equals(false)) {
      battleBtn.setVisibility(View.INVISIBLE);
    }
    if (ingame.equals(false)) {
      newgameBtn.setVisibility(View.INVISIBLE);
    }
    

    As you’re aware that ListView items are recycled (that’s why you should use a ViewHolder), you also need to set the buttons to View.VISIBLE when the condition is true.

    Your code should look like this:

    if (battle.equals(false)) {
      battleBtn.setVisibility(View.INVISIBLE);
    } else {
      battleBtn.setVisibility(View.VISIBLE);
    if (ingame.equals(false)) {
      newgameBtn.setVisibility(View.INVISIBLE);
    } else {
      newgameBtn.setVisibility(View.VISIBLE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can't work out a way to make an array of buttons in android. This
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can anyone help me trying to find out why this doesn't work. The brushes
Can I order my users in the database, so I don't have to say
Can anyone explain to me why this program: for(float i = -1; i <
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.