Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>try something like this .. import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import android.app.ListActivity; import android.content.Intent; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import com.google.ads.AdRequest; import com.google.ads.AdView; public class AndroidXMLParsingActivity extends ListActivity { static final String KEY_ITEM = "item"; // parent node static final String KEY_ID = "id"; static final String KEY_NAME = "name"; static final String KEY_ADDRESS = "address"; static final String KEY_PHONE = "phone"; static final String KEY_ATTRACTION = "attraction"; String xml; int mIndex; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.display); Intent in = getIntent(); mIndex = Integer.parseInt(in.getStringExtra("value")); ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); XMLParser parser = new XMLParser(); switch (mIndex) { case 0: InputStream stream = getResources() .openRawResource(R.raw.myxml); try { byte[] buffer = new byte[stream.available()]; stream.read(buffer); stream.close(); xml = new String(buffer); } catch (IOException e) { // Error handling } break; } Document doc = parser.getDomElement(xml); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_ITEM); for (int i = 0; i &lt; nl.getLength(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); Element e = (Element) nl.item(i); map.put(KEY_ID, parser.getValue(e, KEY_ID)); map.put(KEY_NAME, parser.getValue(e, KEY_NAME)); map.put(KEY_ADDRESS, parser.getValue(e, KEY_ADDRESS)); map.put(KEY_PHONE, parser.getValue(e, KEY_PHONE)); map.put(KEY_ATTRACTION, parser.getValue(e, KEY_ATTRACTION)); menuItems.add(map); } ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.list_item, new String[] { KEY_NAME, KEY_ADDRESS, KEY_PHONE, KEY_ATTRACTION }, new int[] { R.id.name, R.id.desciption, R.id.cost, R.id.sttraction }); setListAdapter(adapter); ListView lv = getListView(); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { String val = "" + mIndex; Intent i = new Intent(getApplicationContext(), MallFinderActivity.class); i.putExtra("value", val); i.putExtra("position", "" + position); String mallName = ((TextView) view.findViewById(R.id.name)) .getText().toString(); i.putExtra("mall", mallName); startActivity(i); } }); } } this is my listitem xml : &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;!-- Name Label --&gt; &lt;TextView android:id="@+id/name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#dc6800" android:textSize="16sp" android:textStyle="bold" /&gt; &lt;!-- Description label --&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Address: " android:textColor="#5d5d5d" android:textStyle="bold" &gt; &lt;/TextView&gt; &lt;TextView android:id="@+id/desciption" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#000000" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; &lt;!-- Linear layout for cost and price Cost: Rs.100 --&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;!-- Cost Label --&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Phone: " android:textColor="#5d5d5d" android:textStyle="bold" &gt; &lt;/TextView&gt; &lt;!-- Price Label --&gt; &lt;TextView android:id="@+id/cost" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:textColor="#000000" android:textStyle="bold" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;!-- Cost Label --&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Attraction: " android:textColor="#5d5d5d" android:textStyle="bold" &gt; &lt;/TextView&gt; &lt;!-- Price Label --&gt; &lt;TextView android:id="@+id/sttraction" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:textColor="#000000" android:textStyle="bold" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; this is main.xml &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/mainlayoutsecond" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight=".1" android:orientation="vertical" &gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#E3E3E3" android:divider="#b5b5b5" android:dividerHeight="1dp" android:fastScrollEnabled="true" android:focusable="false" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload