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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:55:38+00:00 2026-06-09T14:55:38+00:00

I have created this simple android Activity to demonstrate my problem. I just want

  • 0

I have created this simple android Activity to demonstrate my problem.

I just want the screen to have a textInput, and a button. Below these two, I want to create a ListView if the button is pressed (The button basically calls some method and gets an array of String. I want the ListView to display this array.

So its a plain Screen, a button, a text input, when button pressed it calls a method and receives an array of string and want to Print the list underneath them.

public class TagListViewer  extends ListActivity {

    private Button clickBtn;
    EditText textInput;
    String[] resultStr = {"a", "b", "c"}; //Ideally would want this inside the button OnClickListener... but couldn't bcz I needed one for the Array adapter.

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.tagselection);

        clickBtn = (Button) findViewById(R.id.CreatePL);
        clickBtn.setText("Search");
        textInput = (EditText) findViewById(R.id.textInput);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, resultStr);
        setListAdapter(adapter);

        clickBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter();

                adapter.add("ABC"); //This I could use the array I get to add its elements
                adapter.notifyDataSetChanged();
            }

        });
    }
}
  • 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-09T14:55:39+00:00Added an answer on June 9, 2026 at 2:55 pm

    I’m not certain what your question is, but I noticed that you are trying to add items to a primitive String array and creating two different adapters… I have a hunch about the problem. Look at the simple changes below:

    public class TagListViewer  extends ListActivity {
        // Make adapter a class variable
        private ArrayAdapter<String> adapter;
    
        private Button clickBtn;
        EditText textInput;
    
        // You cannot add items to a primitive String array, we'll convert this to an ArrayList
        String[] resultStr = {"a", "b", "c"}; 
        List<String> list = new ArrayList<String>();
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tagselection);
    
            // Add contents of resultStr to the dynamic List
            Collections.addAll(list, resultStr);
    
            clickBtn = (Button) findViewById(R.id.CreatePL);
            clickBtn.setText("Search");
            textInput = (EditText) findViewById(R.id.textInput);
    
            // Reflect class variable change and use list instead of resultStr
            adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list);
            setListAdapter(adapter);
    
            clickBtn.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    // This will add the one phrase "ABC"
                    //adapter.add("ABC");
    
                    // This will add the contents of textInput
                    adapter.add(textInput.getText().toString());
                }
            });
        }
    }
    

    Added from comments

    A ListActivity is required to have a ListView with the id android.R.id.list in its layout:

    <ListView android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created this Fiddle with this code: This is my problem I want
I have created a simple game for Android; I want to prevent users from
I have a simple Android app with one Activity. This Activity downloads a small
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have created my web socket server and client using this simple tutorial here
Could someone help me on this, I have created simple web services using axis2
To explain my question I have created this http://jsfiddle.net/Jams/XNVB2/ here I want when div1
I have created a simple app for android, that uses buttons to navigate different
I have a simple android application to access a web service. I want to
I am writing a simple android app which have a edittext and a button.

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.