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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:08:01+00:00 2026-05-22T20:08:01+00:00

I have a simple linearlayout with a textbox a button and a listview, I’m

  • 0

I have a simple linearlayout with a textbox a button and a listview, I’m doing some URL data getting when something is entered in the textbox and the button is pressed I want to parse the results and display in the listview.

What I can’t work out is how to instatiate the listview from within my extende activity class and add it to the layout? I think I’m barking up the wrong tree !

public class HelloAndroid extends Activity{
    /** Called when the activity is first created. */
    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        MyList L;
        L = new MyList();

        //setContentView(L.getListView());

        EditText edittext = (EditText)findViewById(R.id.editText1);
        edittext.setText("");


        Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                try {
                    EditText edittext = (EditText)findViewById(R.id.editText1);
                    executeHttpGet(edittext.getText().toString());
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } 
            }
        });  
    }

    public void executeHttpGet(String vrm) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI("http://xxx/vrmtest.asp?vrm="+vrm));
            HttpResponse response = client.execute(request);
            in = new BufferedReader
            (new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();
            String page = sb.toString();
            System.out.println(page);

            Context context = getApplicationContext();
            CharSequence text = page;
            int duration = Toast.LENGTH_LONG;


            Toast toast = Toast.makeText(context, text, duration);
            toast.show();            

            } finally {
            if (in != null) {
                try {
                    in.close();
                    } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public class MyList extends ListActivity {

        /** Called when the activity is first created. */
        public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            // Create an array of Strings, that will be put to our ListActivity
            String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
                    "Ubuntu", "Solaris", "Android", "iPhone"};
            // Create an ArrayAdapter, that will actually make the Strings above
            // appear in the ListView
            this.setListAdapter(new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, names));
        }

        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
            // Get the item that was clicked
            Object o = this.getListAdapter().getItem(position);
            String keyword = o.toString();
            Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG)
                    .show();
        }
    }    
}

An explanation would suffice rather than code but an example would be nice.

  • 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-22T20:08:01+00:00Added an answer on May 22, 2026 at 8:08 pm

    As long as your main.xml layout file has a ListView in it, you’re on the right path. Set its @+id to something arbitrary and reference it in your code with:

    ListView lv = (ListView) findViewById(R.id.arbitrary_id);
    

    You don’t necessarily need a ListActivity to use a ListView. Simply parse the data that you receive back from the server, put it in an array, and use lv.setAdapter(your_array_adapter) to fill the ListView with your data.

    You can go further and specify your ItemClickListener by:

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
        }
    };
    

    Alternatively, you can create the ListView programmatically using

    ListView lv = new ListView(this);
    

    and adding it to a view in your layout with

    some_container_view_in_main.addView(lv);
    

    Then you would set the ArrayAdapter and OnItemClickListener the same as above.

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

Sidebar

Related Questions

I have a simple little test app written in Flex 3 (MXML and some
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement
I develop tools in Autodesk Maya. Many of the tools I build have simple
Should simple JavaBeans that have only simple getters and setters be unit tested?? What
I have a simple webform that will allow unauthenticated users to input their information,
I have a simple 2-column layout with a footer that clears both the right
I have a simple page with my ScriptManager and my UpdatePanel , and my
I have a simple setter method for a property and null is not appropriate

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.