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 7641127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:50:43+00:00 2026-05-31T08:50:43+00:00

I am trying to construct a multiline ListView backed by an ArrayAdapter. I would

  • 0

I am trying to construct a multiline ListView backed by an ArrayAdapter. I would like each row in the list to have two lines and a delete button next to it. When the delete button is clicked, the items in the arrays should be removed and the ListView should refresh itself.

This is the code for the MainActivity, which has an inner class that is the custom ArrayAdapter:

public class MainActivity extends Activity {
ArrayList<String> artistsList = new ArrayList<String>();
String[] artists = {"Matt Nathanson", "Green Day", "Three Days Grace", "LMFAO", "One Direction", 
        "Linkin Park", "Neon Trees", "Cee Lo Green", "Plain White T's", "Metallica", "Maroon 5",
        "Sick Puppies", "Bruno Mars", "Billy Joel", "Don McLean", "Adele", "Gary Jules"};
ArrayList<String> songsList = new ArrayList<String>();
String[] songs = {"Come On Get Higher", "Holiday", "I Hate Everything About You", "Sexy and I Know It", "What Makes You Beautiful",
        "What I've Done", "Animal", "Fuck You", "Hey There Delilah", "Sandman", "Moves Like Jagger",
        "Rip Tide", "Talking to the Moon", "Piano Man", "American Pie", "Someone Like You", "Mad World"};

ListView list;
TestArrayAdapter mArrayAdapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    for(String s : artists) {
        artistsList.add(s);
    }
    for(String s : songs) {
        songsList.add(s);
    }

    mArrayAdapter = new TestArrayAdapter();

    list = (ListView)findViewById(R.id.mainlist);

    list.setAdapter(mArrayAdapter);
}


class TestArrayAdapter extends ArrayAdapter<String> {

    public TestArrayAdapter() {
        super(MainActivity.this, R.layout.row, songs);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = getLayoutInflater();
        View row=inflater.inflate(R.layout.row, parent, false);

        TextView primaryTextView = (TextView)row.findViewById(R.id.primaryTextView);
        TextView secondaryTextView = (TextView)row.findViewById(R.id.secondaryTextView);

        primaryTextView.setText(songsList.get(position));
        secondaryTextView.setText(artistsList.get(position));

        ImageView deleteButton = (ImageView)row.findViewById(R.id.deleteRowButton);
        deleteButton.setTag(position);
        deleteButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                artistsList.remove(v.getTag());
                songsList.remove(v.getTag());
                mArrayAdapter.notifyDataSetChanged();
            }
        });

        return row;
    }
}

Calling notifyDataSetChanged() does not seem to do anything; however, the items in the ArrayLists are being deleted. The ListView seems to be independent of changes that I make in the ArrayLists and the ArrayAdapter. Ideally, when I remove an item from the underlying data, I should be able to call notifyDataSetChanged() and the ListView will update itself.

I have looked at the other questions similar to this, but all of them have only a single ArrayList providing data to the ListView, and I can’t figure out how to adapt those solutions for multiline rows. Thanks in advance.

  • 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-05-31T08:50:44+00:00Added an answer on May 31, 2026 at 8:50 am

    I wrote a tutorial recently on how to create a similar listview. Check it out here

    http://www.shubhayu.com/android/listview-with-arrayadapter-and-customized-items

    This would help you in creating what you want except the deletion part. The deletion will not be difficult after that. You just need to handle it on the onClick of your delete button. I’ll guide you through it once you get the list up and running.

    Also, override you getCount(). That should do the trick.

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

Sidebar

Related Questions

Trying to construct a query such that I have multiple statement specifying joins, each
I am trying to construct a SpannableString such that it looks like this: Two
I am trying to construct a TreeView from a Menu. My Code is like
I'm currently trying to construct a list of bean classes in Java from a
I have been trying to construct a checkbox node tree . My specification is
I'm trying to construct a Link. The resulting Link should look something like this:
I'm trying to construct a linq query that pulls all nodes that have a
I'm trying to construct a little mobile optimized web. This web list a set
I'm trying to construct two components that communicate via UDP sockets. Component 1 is
I'm trying to construct a page layout that will look something like this: In

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.