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

  • Home
  • SEARCH
  • 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 9020927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:08:12+00:00 2026-06-16T05:08:12+00:00

When the user clicks a button, a new string is added to the list

  • 0

When the user clicks a button, a new string is added to the list view, but nothing is appearing when i click it. How exactly would I do that?

MatchesList.java
The class that adds the strings to the list view

import java.util.ArrayList;

import com.actionbarsherlock.app.SherlockListActivity;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;

public class MatchesList extends SherlockListActivity{
    ArrayList<String> listItems = new ArrayList<String>();
    ArrayAdapter<String> adapter;

    int matchNum=0;
    Button addMatch;

    @Override
    public void onCreate(Bundle icicle){
        super.onCreate(icicle);
        setContentView(R.layout.fragment_matches);
        adapter= new ArrayAdapter<String>(this, 
                android.R.layout.simple_list_item_1, 
                listItems);

        setListAdapter(adapter);

        addMatch = (Button) findViewById(R.id.addMatchBtn);
        addMatch.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
            addMatch(v);
            }
        });


    }

    public void addMatch(View view){
        matchNum += 1;
        listItems.add("Match " + matchNum);
        adapter.notifyDataSetChanged();
    }

}

MatchesFragment.java

import com.actionbarsherlock.app.SherlockFragment;

import android.os.Bundle;
import android.view.*;

public class MatchesFragment extends SherlockFragment{

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        return inflater.inflate(R.layout.fragment_matches, container, false);
    }
}

fragment_matches.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MatchesFragment" >

    <Button
        android:id="@+id/addMatchBtn"
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:text="Add a Match"

    />


    <ListView 
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"></ListView>

</LinearLayout>
  • 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-16T05:08:14+00:00Added an answer on June 16, 2026 at 5:08 am

    listAdapter.add(...) instead (and no need to call notifyDataSetChanged() then).

    ArrayAdapter can use another list internally if you are using filter for example, besides not good practice as the ArrayAdapter could just do a defensive copy of that list passed in the constructor (it doesn’t though). It is using an internal lock to protect that list though. So really isn’t supposed to modify it outside.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When the user clicks on a button, a new ListFragment is displayed. This fragment
How can I force validation when user clicks button? One would think this should
There is a case that when a user presses the button a new TextView
I am implementing a UIlabel that displays the result of a user's button clicks
When the user clicks a button, I want his browser to automatically scroll to
My goal: the user clicks a button. From the button pops up a two-level
What I want to do is when a user clicks a button, to change
I want my recaptcha to appear only after user clicks submit button on the
In my typical app, the user clicks a button in an aspx page, invokes
I want to, when the user clicks a button on my website, to make

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.