Wednesday 15 June 2011

android - PopupMenu button not working -


I have a button in the activity when I click on a button then it displays the popup menu. I need to show the gallery in the page below. But the IM error is happening. " ConstructorManactivity.IJAadapter (New popup menu.OnMainiteClickList () {}) is undefined "

Code:

main.xml: & lt; Relative layout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/toolsAndroid: mess =" @ dimen / activity_vertical_margin "Android : PaddingLeft = "@ dimen / activity_horizontal_margin" Android: paddingRight = "@ dimen / activity_horizontal_margin" Android: paddingTop = "Android: @ daemon / activity_version_mergin" tools: reference = ". Main activity "& gt; Button Android: id =" @ + id / popup_but_id "Android: layout_height =" wrap_content "Android: layout_width =" wrap_content "android: text =" popup_button "/> gt; gallery Android: id = "@ + id / gallery1" android: layout_marginTop = "300dp" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" /> & lt; / relativeLayout & gt;

MainActivity.java:

  the expansion of the MainActivity activity of the public class (button popup_but; extension of the public class image adapter base adapter (reference reference; int itembackground; Vignette image adapter (reference C) {reference = c; // --- setting style --- typed arrowArray style = properties (R. // R.styleable.Gallery1_android_galleryItemBackground, 0); // a.recycle ();} // --- returns the number of images --- public int getCount () {return imageIDs.length;} // --- Returns the item --- Receives public object (status of int) {Return Status; } // - Returns the id of an item --- the public last ITMID (status of the return) {return status; } // --- Allows an image view --- @ Override public view getView (see the status of int, viewview, ViewGroup parent) {// Tudo Auto-Generated Method View Stub image view image; If (convertView == empty) {imageView = New ImageView (reference); // Set the ImageView to display in the image // the user selected position on the array. ImageView.setImageResource (imageIDs [status]); ImageView.setScaleType (ImageView.ScaleType.FIT_XY); ImageView.setLayoutParams (New Gallery. LayoutParams (150, 120)); // imageView.setLayoutParams (New Gallery. LayoutParam (300, 300)); } And {imageView = (ImageView) ConvertView; } ImageView.setBackgroundResource (itemBackground); See return image; }} Integer [] imageIDs = {R.drawable.tab, R.drawable.tab1, R.drawable.tab2, R.drawable.tab3, R.drawable.tab4, R.drawable.tab5, R.drawable.tab6, R.drawable.tab7}; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.activity_main); Popup_bat = (button) FindById (R.id.popup_but_id); Popup_butksetOnClickListener (new OnClickListener () {@Override public void onClick (View v) {// TODO Auto-generated method stub Popapmenu popup = new Popapmenu (main Aektivitikis, Popap_bt); Popapkgetmenuinflatr (). Menu .main, popup.getMenu ()); PopupksetOnMenuItemClickListener (new OnMenuItemClickListener () {@Override Public booolan onMenuItemClick (MenuItem item) {// TODO Auto-generated method stub switch (item.getItemId ()) {case R. Id.add: gallery = (Gallery) searching for ViewById (R.id.gallery1); Gallery .Setadator (New ImageAdapter (this)); Break; Case R.id.sub: break; case R.id.mul: break; Case R.id.div: break;} Truth back;}}); Popup.show ();}}); } @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Enhancing Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Fluo (R. menu menu, menu); Back true; }}    

gallery.setAdapter (New ImageAdapter (this)); The "This" popup menu item in the above row of your code is a symbol of the click listener, while the constructor requires an application context in the image adapter class. Bottom line gallery. Try to give context primarily as SetAdapter (New ImageAdapter (MainActivity.This).);

No comments:

Post a Comment