android - ListView Not Working -



android - ListView Not Working -

i have made simple listview , want buttons correspond new activity have used case statement happen heres code.

bundle com.example.lookingatics; 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.textview; public class otheractivity extends activity{ @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.other_activity); listview listview = (listview) findviewbyid(r.id.mylist); final string[] values = new string[] { "science", "maths", "english", "history", "geography", "r.e", "i.c.t", "arabic", "art", "mainactivity" }; // define new adapter // first parameter - context // sec parameter - layout row // 3rd parameter - id of textview info written // forth - array of info arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_selectable_list_item, android.r.id.text1, values); // assign adapter listview listview.setadapter(adapter); listview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { final textview mtextview = (textview)view; switch (position) { case 0: intent newactivity0 = new intent("com.example.lookingatics.otheractivity"); startactivity(newactivity0); break; case 1: intent newactivity1 = new intent("com.example.lookingatics.mainactivity"); startactivity(newactivity1); break; case 2: intent newactivity2 = new intent("com.example.lookingatics.otheractivity"); startactivity(newactivity2); break; case 3: intent newactivity3 = new intent("com.example.lookingatics.mainactivity"); startactivity(newactivity3); break; default: // nil do! } } }); } }

and here's manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lookingatics" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="2" android:targetsdkversion="17" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.lookingatics.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.example.lookingatics.otheractivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.other" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> </application> </manifest>

does know problem , why maintain on getting app saying not responding?

modify manifest file.

your manifest code <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.lookingatics.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.example.lookingatics.otheractivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.other" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> </application>

make changes in file.. seek this

<application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.lookingatics.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.example.lookingatics.otheractivity" android:label="other activity" > </activity> </application> intent intent = new intent (otheractivity.this, nameofyouractivityyouwanttostart.class); startactivity(intent);

android android-listview

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -