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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:41:43+00:00 2026-06-14T00:41:43+00:00

Possible Duplicate: how to get specific value in xml parsing by write in edittext

  • 0

Possible Duplicate:
how to get specific value in xml parsing by write in edittext

This code does not compile whats wrong in this code? Is not say application stop unexpectedly did I do correctly everything? Please check it I want to add an EditText which take input and check its value from XML file and show on screen I followed this Tutorial

      static final String URL = "http://api.androidhive.info/pizza/?format=xml";
// XML node keys
static final String KEY_ITEM = "item"; // parent node
static final String KEY_ID = "id";
static final String KEY_NAME = "name";
static final String KEY_COST = "cost";
static final String KEY_DESC = "description";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
       EditText et = (EditText)findViewById(R.id.editText1);

               ArrayList<HashMap<String, String>> menuItems = new 
     ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_ITEM);
        // looping through all item nodes <item>
        for (int i = 0; i < nl.getLength(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);
            // adding each child node to HashMap key => value
           if(parser.getValue(e, KEY_ID).equals(et.getText().toString())){

            map.put(KEY_ID, parser.getValue(e, KEY_ID));
            map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
            map.put(KEY_COST, "Rs." + parser.getValue(e, KEY_COST));
            map.put(KEY_DESC, parser.getValue(e, KEY_DESC));

            // adding HashList to ArrayList
            menuItems.add(map);
            }

      }
        // Adding menuItems to ListView
        ListAdapter adapter = new SimpleAdapter(this, menuItems,
                R.layout.list_item,
                new String[] { KEY_NAME, KEY_DESC, KEY_COST }, new int[] {
                        R.id.name, R.id.desciption, R.id.cost });

        setListAdapter(adapter);

        // selecting single ListView item
        ListView lv = getListView();
                // listening to single listitem click
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // getting values from selected ListItem
                String name = ((TextView) 
       view.findViewById(R.id.name)).getText().toString();
                String cost = ((TextView) 
    view.findViewById(R.id.cost)).getText().toString();
                String description = ((TextView) 
    view.findViewById(R.id.desciption)).getText().toString();

                // Starting new intent
                Intent in = new Intent(getApplicationContext(),  
    SingleMenuItemActivity.class);
                in.putExtra(KEY_NAME, name);
                in.putExtra(KEY_COST, cost);
                in.putExtra(KEY_DESC, description);
                startActivity(in);

            }
        });
    }
}

main.xml file–>>

          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical">
<!-- Main ListView 
     Always give id value as list(@android:id/list)
-->

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



    <EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

  • 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-14T00:41:45+00:00Added an answer on June 14, 2026 at 12:41 am

    try this code,

    public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                   EditText et = (EditText)findViewById(R.id.editText1);
    
                           ArrayList<HashMap<String, String>> menuItems = new 
                 ArrayList<HashMap<String, String>>();
    
                    XMLParser parser = new XMLParser();
                    String xml = parser.getXmlFromUrl(URL); // getting XML
                    Document doc = parser.getDomElement(xml); // getting DOM element
    
                    NodeList nl = doc.getElementsByTagName(KEY_ITEM);
                    // looping through all item nodes <item>
                    for (int i = 0; i < nl.getLength(); i++) {
                        // creating new HashMap
                        Element e = (Element) nl.item(i);
                        // adding each child node to HashMap key => value
                       if(parser.getValue(e, KEY_ID).equals(et.getText().toString())){
                           String name = parser.getValue(e, KEY_NAME);
                           String cost = "Rs." + parser.getValue(e, KEY_COST);
                           String description = parser.getValue(e, KEY_DESC);
                           Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                           in.putExtra(KEY_NAME, name);
                           in.putExtra(KEY_COST, cost);
                           in.putExtra(KEY_DESC, description);
                           startActivity(in);
                        }
    
                  }
        }
    

    and in the SingleMenuItemActivity class, fetch the values using,

        String name = this.getIntent().getStringExtra("KEY_NAME");
    String cost= this.getIntent().getStringExtra("KEY_NAME");
    String description= this.getIntent().getStringExtra("KEY_DESC");
    

    Edit-

    main.xml file–>>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical">
    
    
        <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />
    
    </LinearLayout>
    

    Extend your Activity from the Activity class

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

Sidebar

Related Questions

Possible Duplicate: What are the reasons why Map.get(Object key) is not (fully) generic This
Possible Duplicate: Android: How to get values in under specific xml tags Hi guys,
Possible Duplicate: In C, how do I get a specific range of numbers from
Possible Duplicate: Get a list of dates between two dates This is my sql:
Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
Possible Duplicate: php get microtime from date string For a specific purpose, I need
Possible Duplicate: How can I get a specific parameter from location.search? I have a
Possible Duplicate: way to get specific integer(s) from a double data type C++ So
Possible Duplicate: ROW_NUMBER() in MySQL Is this possible? I want to get a bunch
Possible Duplicate: get the value of an url response with curl I have an

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.