Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to go to a particular activity on list item click?
    primarykey
    data
    text
    <p>I am developing an application in android in which i creating a list view of few items. I want to call a class on each list item click.Here is my code</p> <pre><code>import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import com.example.listview.abc; public class listview extends Activity implements OnItemClickListener { public ListView lv1; public String[] names = { "Abc", "Xyz", "Pqr", "Jap", "Jay", "bla bla" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lv1 = (ListView) findViewById(R.id.list); lv1.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, names)); lv1.setOnItemClickListener(this); } @Override public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) { if(position==0){ Intent i = new Intent(this, abc.class); startActivity(i); //Toast.makeText(this, "You pressed the first item in the list", // Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "You pressed all other items in the list", Toast.LENGTH_SHORT).show(); } // else if(position==1){ // start another activity here... } </code></pre> <p>The problem is that when i click the first item it crashes but the click on other item shows the message but when i click on the item for next activity it crashes i tried to follow this question of stackoverflow but it didn't work { <a href="https://stackoverflow.com/questions/4582757/how-to-jump-from-listview-to-next-activityclass-in-android">How to jump from ListView to next Activity</a> } here is some part of log cat</p> <pre><code>06-09 12:29:52.111: DEBUG/AndroidRuntime(903): Shutting down VM 06-09 12:29:52.181: INFO/AndroidRuntime(903): NOTE: attach of thread 'Binder Thread #3' failed 06-09 12:29:52.181: INFO/ActivityManager(60): Start proc com.example.listview for activity com.example.listview/.listview: pid=910 uid=10039 gids={} 06-09 12:29:52.310: DEBUG/dalvikvm(903): Debugger has detached; object registry had 1 entries 06-09 12:29:54.670: INFO/ActivityManager(60): Displayed activity com.example.listview/.listview: 2616 ms (total 199904 ms) 06-09 12:29:55.249: DEBUG/dalvikvm(253): GC_EXPLICIT freed 176 objects / 12384 bytes in 3461ms 06-09 12:29:59.940: DEBUG/dalvikvm(125): GC_EXPLICIT freed 878 objects / 48664 bytes in 188ms 06-09 12:30:05.270: DEBUG/dalvikvm(262): GC_EXPLICIT freed 46 objects / 2240 bytes in 183ms 06-09 12:30:50.140: DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol 06-09 12:32:52.731: DEBUG/dalvikvm(120): GC_FOR_MALLOC freed 9850 objects / 473648 bytes in 1222ms 06-09 12:35:50.171: DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol 06-09 12:40:50.240: DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol 06-09 12:45:50.311: DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol </code></pre> <p>And the menifest File is</p> <p>**</p> <blockquote> <p>**</p> </blockquote> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" &gt; package="com.example.listview" android:versionCode="1" &gt; android:versionName="1.0"&gt; &gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &gt; &lt;activity android:name=".listview" android:label="@s tring/app_name"&gt; &gt; &gt; &lt;intent-filter&gt; &gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &gt; &lt;/intent-filter&gt; &gt; &lt;/activity&gt; &gt; &gt; &lt;activity android:enabled="true" android:name="abc" /&gt; &gt; &lt;/application&gt; &gt; &lt;uses-sdk android:minSdkVersion="3" /&gt; &gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &gt; &lt;/manifest&gt; </code></pre> <p>**</p> <p>** </p> <p>Please have a look at the code and help me out</p> <p>Thanks in advance..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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