Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing value of item clicked in list view from one screen to another in android
    text
    copied!<p>I am trying to send the item clicked in list to another screen but getting an error... </p> <p>Heres my main file...</p> <pre><code>package com.bmc; 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.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; 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. */ private Context mCtx; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.myrequest); mCtx = this; 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(); String selectedFromList = (String) (lv.getItemAtPosition(position)); Intent i = new Intent(mCtx, Details.class); Bundle extras=new Bundle(); extras.putSerializable("obj_to_pass", selectedFromList); i.putExtras(extras); startActivity(i); // Main.this.finish(); } }); } } </code></pre> <p>Heres my Details.java file...</p> <pre><code>package com.bmc; import android.app.Activity; import android.os.Bundle; import android.widget.EditText; public class Details extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.details); EditText txt; Bundle extras = getIntent().getExtras(); Object my_obj = extras.getSerializable("obj_to_pass"); txt=(EditText) findViewById(R.id.editText_desc1); txt.setText((CharSequence) my_obj); } } </code></pre> <p>Log file...</p> <pre><code>12-27 01:46:55.994: E/AndroidRuntime(311): FATAL EXCEPTION: main 12-27 01:46:55.994: E/AndroidRuntime(311): java.lang.ClassCastException: java.util.HashMap 12-27 01:46:55.994: E/AndroidRuntime(311): at com.bmc.Main$1.onItemClick(Main.java:73) 12-27 01:46:55.994: E/AndroidRuntime(311): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 12-27 01:46:55.994: E/AndroidRuntime(311): at android.widget.ListView.performItemClick(ListView.java:3382) 12-27 01:46:55.994: E/AndroidRuntime(311): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) 12-27 01:46:55.994: E/AndroidRuntime(311): at android.os.Handler.handleCallback(Handler.java:587) 12-27 01:46:55.994: E/AndroidRuntime(311): at android.os.Handler.dispatchMessage(Handler.java:92) 12-27 01:46:55.994: E/AndroidRuntime(311): at android.os.Looper.loop(Looper.java:123) 12-27 01:46:55.994: E/AndroidRuntime(311): at android.app.ActivityThread.main(ActivityThread.java:4627) 12-27 01:46:55.994: E/AndroidRuntime(311): at java.lang.reflect.Method.invokeNative(Native Method) 12-27 01:46:55.994: E/AndroidRuntime(311): at java.lang.reflect.Method.invoke(Method.java:521) 12-27 01:46:55.994: E/AndroidRuntime(311): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 12-27 01:46:55.994: E/AndroidRuntime(311): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 12-27 01:46:55.994: E/AndroidRuntime(311): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>After running above project am getting error and msg box with option "Force Close"... So if anyone has solution then help...!!! thanx..!!</p>
 

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