Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change the screen in android after clicking on ListItem using Intent and ListActivity
    text
    copied!<p>Following is the code I am working with. I am getting a runtime error after clicking on a list item. I should go to next screen, but I get an error: <code>the application has stopped unexpectedly</code>. Could you please tell me what's wrong?</p> <pre><code>package com.pxr.tutorial.xmltest; 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.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.Toast; public class Main extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myrequest(); } void myrequest() { setContentView(R.layout.myrequest); ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); String xml = XMLfunctions.getXML("http://10.0.2.2/ss.htm"); Document doc = XMLfunctions.XMLfromString(xml); int numResults = XMLfunctions.numResults(doc); if((numResults &lt;= 0)){ Toast.makeText(Main.this, "Error", Toast.LENGTH_LONG).show(); finish(); } NodeList nodes = doc.getElementsByTagName("result"); for (int i = 0; i &lt; nodes.getLength(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); Element e = (Element)nodes.item(i); map.put("id", XMLfunctions.getValue(e, "id")); map.put("name", XMLfunctions.getValue(e, "id") + "-" + XMLfunctions.getValue(e, "name") + " :"); mylist.add(map); } ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main, new String[] { "name"}, new int[] { R.id.item_title }); setListAdapter(adapter); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { @SuppressWarnings("unchecked") HashMap&lt;String, String&gt; o = (HashMap&lt;String, String&gt;) lv.getItemAtPosition(position); Toast.makeText(Main.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_LONG).show(); Main.this.finish(); Intent i = new Intent(Main.this, Details.class); startActivity(i); // details(o.get("id")); } }); } void details(String id) { Details dt=new Details(); dt.det(id); // setContentView(R.layout.details); } } </code></pre> <p><code>Details.java</code> file is : </p> <pre><code>package com.pxr.tutorial.xmltest; import android.app.Activity; import android.os.Bundle; public class Details extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple); } } </code></pre>
 

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