java - Error with listview in dialog -
i have been on error while. trying open list view in dialog not opening me code.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mybasicapp" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".slashscreen" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".menu" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.menu" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".tutorialsone" android:label="@string/title_activity_main" > <intent-filter> <action android:name="com.mybasicapp.tutorialsone" /> <category android:name="android.intent.category.default" />
java code:
public class menu extends activity{ button imagebuttonopendialog; string key_textpss = "textpss"; static final int custom_dialog_id = 0; listview dialog_listview; string[] listcontent = { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"}; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); imagebuttonopendialog = (button)findviewbyid(r.id.imgbtn1); imagebuttonopendialog.setonclicklistener(new button.onclicklistener(){ public void onclick(view arg0) { showdialog(custom_dialog_id); }}); } @override protected dialog oncreatedialog(int id) { dialog dialog = null; switch(id) { case custom_dialog_id: dialog = new dialog(menu.this); dialog.setcontentview(r.layout.custom); dialog.settitle("custom dialog"); dialog.setcancelable(true); dialog.setcanceledontouchoutside(true); dialog.setoncancellistener(new oncancellistener(){ public void oncancel(dialoginterface dialog) { // todo auto-generated method stub toast.maketext(menu.this, "oncancellistener", toast.length_long).show(); }}); dialog.setondismisslistener(new ondismisslistener(){ public void ondismiss(dialoginterface dialog) { // todo auto-generated method stub toast.maketext(menu.this, "ondismisslistener", toast.length_long).show(); }}); //prepare listview in dialog dialog_listview = (listview)dialog.findviewbyid(r.id.dialoglist); arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, listcontent); dialog_listview.setadapter(adapter); dialog_listview.setonitemclicklistener(new onitemclicklistener(){ public void onitemclick(adapterview<?> parent, view view, int position, long id) { // todo auto-generated method stub toast.maketext(menu.this, parent.getitematposition(position).tostring() + " clicked", toast.length_long).show(); dismissdialog(custom_dialog_id); }}); break; } return dialog; } @override protected void onpreparedialog(int id, dialog dialog, bundle bundle) { // todo auto-generated method stub super.onpreparedialog(id, dialog, bundle); switch(id) { case custom_dialog_id: // break; } } }
activity_main xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/carbon" > <framelayout android:id="@+id/framelayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_marginbottom="0dp" android:background="@drawable/bottombar" > </framelayout> <imagebutton android:id="@+id/imgbtn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="42dp" android:layout_margintop="79dp" android:src="@android:drawable/btn_star" /> <imagebutton android:id="@+id/imgbtn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_aligntop="@+id/imgbtn1" android:layout_marginright="46dp" android:src="@android:drawable/btn_star" /> <imagebutton android:id="@+id/imagebutton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imgbtn1" android:layout_below="@+id/imgbtn1" android:layout_margintop="36dp" android:src="@android:drawable/btn_star" /> <imagebutton android:id="@+id/imagebutton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imgbtn2" android:layout_aligntop="@+id/imagebutton3" android:src="@android:drawable/btn_star" /> <imagebutton android:id="@+id/imagebutton5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imagebutton3" android:layout_below="@+id/imagebutton3" android:layout_margintop="49dp" android:src="@android:drawable/btn_star" /> <imagebutton android:id="@+id/imagebutton6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imagebutton4" android:layout_aligntop="@+id/imagebutton5" android:src="@android:drawable/btn_star" /> <imagebutton android:id="@+id/imagebutton7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imagebutton5" android:layout_below="@+id/imagebutton5" android:layout_margintop="42dp" android:src="@android:drawable/btn_star" /> <imagebutton android:id="@+id/imagebutton8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imagebutton6" android:layout_aligntop="@+id/imagebutton7" android:src="@android:drawable/btn_star" /> <imageview android:id="@+id/imageview11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:src="@drawable/kj" />
custom.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/customdialog" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="20dp" android:minwidth="300dp"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher"/> <listview android:id="@+id/dialoglist" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <imagebutton android:id="@+id/imagebutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/kj" /> </linearlayout>
also looked on java code again , found code had (button) in xml had image button have change java code can see @ moment..still no luck.i don't know how copy log cast
from count, buttonopendialog
null
getting npe
when try add listener
it. check activity_main
have button
id of im1
. misspelled id or 1 doesn't exist in layout
. if don't see problem post activity_main.xml
.
also, isn't problem should consider using java standard naming conventions. class names should start capital letter. have main
instead of main
class name.
when post question please post logcat in question makes easier members read needing follow link isn't of best quality.
Comments
Post a Comment