为每个gridview项目创建d出窗口-Android

为每个gridview项目创建d出窗口-Android,第1张

概述我正在为饭店的食品订购系统开发一个Android应用程序.在我的项目中,我有一个Gridview,当在gridview中单击项目上的按钮时,我想要一个包含一些文本字段,按钮等的d出窗口.我从thisdocumentexample得到了帮助上面的文档示例可以作为单个应用程序单独工作.这只是创建基本d出窗口

我正在为饭店的食品订购系统开发一个Android应用程序.
在我的项目中,我有一个GrIDvIEw,当在grIDvIEw中单击项目上的按钮时,我想要一个包含一些文本字段,按钮等的d出窗口.

我从this document example得到了帮助

上面的文档示例可以作为单个应用程序单独工作.这只是创建基本d出窗口的示例.但是我需要在GrIDvIEw上使用它.

我的工作->

而不是在文档的main.xml和PopUpWinndowDemoActivity.java之上(它是主要活动),
我使用了grID_single.xml及其实现文件GrID_single.java.

但这对我不起作用.当我单击每个项目的按钮时,没有按我希望的那样显示d出窗口.因此,请帮助我解决这个问题,或者给我一个有关网格视图项目d出窗口的工作示例.
我已经附上了我的文件.
等待您的帮助,
谢谢!

GrID_single.java

    button btnClosePopup;    button btnCreatePopup;    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.grID_single);        btnCreatePopup = (button) findVIEwByID(R.ID.addToCart);        btnCreatePopup.setonClickListener(new OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                initiatePopupWindow();            }        });        btnCreatePopup.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw vIEw) {                initiatePopupWindow();            }        });    }    private PopupWindow pwindo;    private voID initiatePopupWindow() {        try {            // We need to get the instance of the LayoutInflater            LayoutInflater inflater = (LayoutInflater) GrID_Single_Popup.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);            VIEw layout = inflater.inflate(R.layout.screen_popup, (VIEwGroup) findVIEwByID(R.ID.popup_element));            pwindo = new PopupWindow(layout, 300, 370, true);            pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);            btnClosePopup = (button) layout.findVIEwByID(R.ID.btn_close_popup);            btnClosePopup.setonClickListener(cancel_button_click_Listener);        } catch (Exception e) {            e.printstacktrace();        }    }    private OnClickListener cancel_button_click_Listener = new OnClickListener() {        public voID onClick(VIEw v) {            pwindo.dismiss();        }    };

grID_single.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"              xmlns:tools="http://schemas.androID.com/tools"              androID:orIEntation="vertical"              androID:layout_wIDth="match_parent"              androID:layout_height="match_parent"              androID:layout_margintop="15dp"              androID:padding="5dp"              androID:ID="@+ID/grID_single_back"        >    <ImageVIEw            androID:ID="@+ID/grID_image"            androID:layout_wIDth="150dp"            androID:layout_height="150dp">    </ImageVIEw>    <TextVIEw            androID:ID="@+ID/grID_text"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_margintop="2dp"            androID:textSize="24dp" >    </TextVIEw>    <button                        androID:layout_wIDth="wrap_content"            androID:layout_height="35dp"            androID:text="Cutomize &amp; Add"            androID:ID="@+ID/addToCart"            androID:layout_gravity="center_horizontal"            androID:layout_margintop="5dp"            androID:layout_marginRight="5dp"            androID:textSize="18dp"            androID:padding="5sp"/></linearLayout>

提前致谢

解决方法:

这对我有用,请检查一次

在网格适配器中:

public CustomGrID(String[] web, int[] ImageID, GrID_single activity) {    this.ImageID = ImageID;    this.web = web;    this.activity = activity;}

在适配器的getVIEw方法中,保持如下所示:

grID = inflater.inflate(R.layout.grID_single, null);TextVIEw textVIEw = (TextVIEw) grID.findVIEwByID(R.ID.grID_text);ImageVIEw imageVIEw = (ImageVIEw) grID.findVIEwByID(R.ID.grID_image);button btnPopup = (button) grID.findVIEwByID(R.ID.btnPopup);btnPopup.setonClickListener(activity);

GrID_single应该实现OnClickListener,并保持如下所示:

@OverrIDepublic voID onClick(VIEw v) {    switch (v.getID()) {    case R.ID.btnPopup:        initiatePopupWindow(web[grID.getpositionForVIEw(v)]);        break;    default:        break;    }}
总结

以上是内存溢出为你收集整理的为每个gridview项目创建d出窗口-Android全部内容,希望文章能够帮你解决为每个gridview项目创建d出窗口-Android所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1120518.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存