如何使对话框布局与MainActivity类中的Gridview交互

时间:2018-07-19 23:31:26

标签: android android-studio gridview dialog

我有一个可调用已安装应用程序的gridview 我有一个对话框layout.xml,当单击GridView中的项目时,该对话框称为 我需要做的是使用对话框中的按钮调用方法卸载应用程序

我需要将操作返回到gridview示例:使用对话框布局中的按钮删除gridview中的项目

            Dialog myDialog;
			...
			myDialog=new Dialog(this);
			...
			// long click
            grdView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(final AdapterView<?> adapterView, View view, final int i, long l) {
				
                        myDialog.setContentView(R.layout.dialog_menu);
                        myDialog.show();
						
                    return true;
                    }
            });
			
			
			
			*Button1
			Uri uri = Uri.fromParts("package", strPackageName, null); 
			Intent it = new Intent(Intent.ACTION_DELETE, uri); 
			startActivity(it); 
			
			*Button2

enter image description here

1 个答案:

答案 0 :(得分:0)

首先,您必须使显示此类对话框的功能

WITH ORDERED AS (
 SELECT
  *,
  ROW_NUMBER() OVER(ORDER BY age ASC) AS ROWNUM
FROM
  `data`
)
SELECT
  age AS percentile50
FROM
  ORDERED
WHERE
  ROWNUM = (
    SELECT CEILING(50 / 100.00 * (COUNT(*) + 1)) FROM ORDERED
  )

然后在gridview项单击中调用此函数。

public void showDialog(){  

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.dialog_menu, null);
    final AlertDialog dialog = builder.create();
    dialog.setView(dialogView);
    dialog.show();
 }