参考地址: http://blog.csdn.net/zhyl8157121/article/details/8169172 
                  http://blog.csdn.net/zhyl8157121/article/details/8709048

*************************************************************************
package com.example.ht;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
 
import android.app.Activity; 
import android.app.Dialog; 
//import android.os.Bundle; 
import android.view.Gravity; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
import android.widget.Toast;

public class F2_TC extends ActionBarActivity {

private Button btn1; 
    private Button btn2; 
    private Button btn3; 
    private ListView listView; 
    private SimpleAdapter adapter; 
    private DBUtil dbUtil;

@Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_f2__tc);
  
   btn1 = (Button) findViewById(R.id.btn_all); 
         btn2 = (Button) findViewById(R.id.btn_add); 
         btn3 = (Button) findViewById(R.id.btn_delete); 
         listView = (ListView) findViewById(R.id.listView); 
         dbUtil = new DBUtil(); 
          
         btn1.setOnClickListener(new OnClickListener() { 
              
             @Override 
             public void onClick(View v) { 
                 hideButton(true); 
                 setListView(); 
             } 
         }); 
  
         btn2.setOnClickListener(new OnClickListener() { 
              
             @Override 
             public void onClick(View v) { 
                 hideButton(true); 
                 setAddDialog(); 
             } 
         }); 
  
         btn3.setOnClickListener(new OnClickListener() { 
              
             @Override 
             public void onClick(View v) { 
                 hideButton(true); 
                 setDeleteDialog(); 
             } 
         }); 
 
 ////////////// 
 }
 
 
 //////////////
 
 /**
     * 设置弹出删除对话框
     */ 
    private void setDeleteDialog() { 
         
        final Dialog dialog = new Dialog(F2_TC.this); 
        //dialog.setContentView(R.layout.dialog_delete);
        dialog.setContentView(R.layout.activity_f7__delete);
        dialog.setTitle("输入想要删除的货物的编号"); 
        Window dialogWindow = dialog.getWindow(); 
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); 
        dialogWindow.setGravity(Gravity.CENTER); 
        dialogWindow.setAttributes(lp); 
 
        //final EditText cNoEditText = (EditText) dialog.findViewById(R.id.editText1); 
        final EditText cNoEditText = (EditText) dialog.findViewById(R.id.editText_del);
        Button btnConfirm = (Button) dialog.findViewById(R.id.button1); 
        Button btnCancel = (Button) dialog.findViewById(R.id.button2); 
 
        btnConfirm.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                dbUtil.deleteCargoInfo(cNoEditText.getText().toString()); 
                dialog.dismiss(); 
                hideButton(false); 
                //Toast.makeText(MainActivity.this, "成功删除数据", Toast.LENGTH_SHORT).show();
                Toast.makeText(F2_TC.this, "成功删除数据", Toast.LENGTH_SHORT).show();
            } 
        }); 
 
        btnCancel.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                dialog.dismiss(); 
                hideButton(false); 
            } 
        }); 
         
        dialog.show(); 
    } 
 
    /**
     * 设置弹出添加对话框
     */ 
    private void setAddDialog() { 
 
        //final Dialog dialog = new Dialog(MainActivity.this);
     final Dialog dialog = new Dialog(F2_TC.this);
        //dialog.setContentView(R.layout.dialog_add);
     dialog.setContentView(R.layout.activity_f6_insert);
        dialog.setTitle("输入添加的货物的信息"); 
        Window dialogWindow = dialog.getWindow(); 
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); 
        dialogWindow.setGravity(Gravity.CENTER); 
        dialogWindow.setAttributes(lp); 
 
        final EditText cNameEditText = (EditText) dialog.findViewById(R.id.editText1); 
        final EditText cNumEditText = (EditText) dialog.findViewById(R.id.editText2); 
        Button btnConfirm = (Button) dialog.findViewById(R.id.button1); 
        Button btnCancel = (Button) dialog.findViewById(R.id.button2); 
 
        btnConfirm.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                 
                dbUtil.insertCargoInfo(cNameEditText.getText().toString(), cNumEditText.getText().toString()); 
                dialog.dismiss(); 
                hideButton(false); 
                //Toast.makeText(MainActivity.this, "成功添加数据", Toast.LENGTH_SHORT).show(); 
                Toast.makeText(F2_TC.this, "成功添加数据", Toast.LENGTH_SHORT).show(); 
            } 
        }); 
 
        btnCancel.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                dialog.dismiss(); 
                hideButton(false); 
            } 
        }); 
        dialog.show(); 
    } 
 
    /**
     * 设置listView
     */ 
    private void setListView() { 
 
        listView.setVisibility(View.VISIBLE); 
 
        List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(); 
 
        list = dbUtil.getAllInfo(); 
 
        adapter = new SimpleAdapter( 
                //MainActivity.this,
          F2_TC.this,
                list,  
                //R.layout.adapter_item,
                R.layout.activity_f3__select,
                new String[] { "Cno", "Cname", "Cnum" },  
                new int[] { R.id.txt_Cno, R.id.txt_Cname, R.id.txt_Cnum }); 
 
        listView.setAdapter(adapter); 
 
    } 
 
    /**
     * 设置button的可见性
     */ 
    private void hideButton(boolean result) { 
        if (result) { 
            btn1.setVisibility(View.GONE); 
            btn2.setVisibility(View.GONE); 
            btn3.setVisibility(View.GONE); 
        } else { 
            btn1.setVisibility(View.VISIBLE); 
            btn2.setVisibility(View.VISIBLE); 
            btn3.setVisibility(View.VISIBLE); 
        } 
 
    } 
 
    /**
     * 返回按钮的重写
     */ 
    @Override 
    public void onBackPressed() 
    { 
        if (listView.getVisibility() == View.VISIBLE) { 
            listView.setVisibility(View.GONE); 
            hideButton(false); 
        }else { 
            //MainActivity.this.finish();
         F2_TC.this.finish();
        } 
    } 
 
 /////////////

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.f2__tc, menu);
  return true;
 }

@Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}

*************************************************************************

*************************************************************************
example1:

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ht.F6_insert" >

<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/F6_Form" />

<LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText2"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="54dp"
        android:orientation="horizontal" >

<Button
            android:id="@+id/button1"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text="@string/confirm" />

<Button
            android:id="@+id/button2"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dip"
            android:text="@string/cancel" />
    </LinearLayout>

<EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_centerVertical="true"
        android:ems="10"
        android:hint="@string/add_hint1" />

<EditText
        android:id="@+id/editText2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/editText1"
        android:ems="10"
        android:hint="@string/add_hint2"
        android:inputType="number" />

</RelativeLayout>

*************************************************************************

*************************************************************************
example2

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ht.F7_Delete" >

<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/F7_Form" />

<EditText
        android:id="@+id/editText_del"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/linearLayout1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="66dp"
        android:ems="10"
        android:hint="@string/delete_hint" />

<LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="47dp"
        android:orientation="horizontal" >

<Button
            android:id="@+id/button1"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text="@string/confirm" />

<Button
            android:id="@+id/button2"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dip"
            android:text="@string/cancel" />
    </LinearLayout>

</RelativeLayout>

*************************************************************************

20150618_Andriod _set Dialog_弹出式菜单的更多相关文章

  1. C++ Button右键弹出式菜单

    Button右键弹出式菜单 关键点 用类来实现 的 实现过程 新建1个类  类名CButtonPopMenu 基类CButton 新建1个菜单资源 IDR_MENU1 // ButtonPopMenu ...

  2. Android学习总结——Popup menu:弹出式菜单

    PopupMenu,弹出菜单,一个模态形式展示的弹出风格的菜单,绑在在某个View上,一般出现在被绑定的View的下方(如果下方有空间). 注意:弹出菜单是在API 11和更高版本上才有效的. 核心步 ...

  3. 弹出式菜单(下拉菜单)实现——PopupMenu

    PopupMenu代表弹出式菜单,它会在指定组件上弹出PopupMenu,默认情况下,PopupMenu会显示在该组件的下方或上方.PopupMenu可增加多个菜单项,并可为菜单项增加子菜单. 使用P ...

  4. 使用PopupMenu创建弹出式菜单

    PopupMenu代表弹出式菜单,它会在指定组件上弹出PopupMenu,默认情况下,PopupMenu会显示在该组件的下方或上方.PopupMenu可增加多个菜单项,并可为菜单项增加子菜单. 使用P ...

  5. css3动画:弹出式菜单

    css3动画:弹出式菜单 今天主要来讲讲transition和transform结合做的动画,会举一些现在(2017年)常见的动画例子. 注:本人也接触css3不久,如果写的有纰漏请指出,不喜勿喷. ...

  6. 高级组件——弹出式菜单JPopupMenu

    弹出式菜单JPopupMenu,需要用到鼠标事件.MouseListener必须要实现所有接口,MouseAdapter是类,只写你关心的方法,即MouseAdapter实现了MouseListene ...

  7. Android中创建PopupMenu弹出式菜单

    之前写过一篇创建option menu的文章:Android中创建option menu 本文主要是讲如何创建PopupMenu弹出式菜单 1.首先创建menu文件menu2.xml: <?xm ...

  8. BZOJ_3671_[Noi2014]随机数生成器_set+贪心

    BZOJ_3671_[Noi2014]随机数生成器_set Description   Input 第1行包含5个整数,依次为 x_0,a,b,c,d ,描述小H采用的随机数生成算法所需的随机种子.第 ...

  9. BZOJ_2120_数颜色_Set+树状数组+主席树

    BZOJ_2120_数颜色_Set+树状数组+主席树 Description 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L ...

随机推荐

  1. Java基础之写文件——使用多个视图缓冲区(PrimesToFile2)

    控制台程序.本例将对应于每个素数的数据以三个连续数据项的形式写入: 1.以二进制值表示的字符串长度值(最好是整型,但本例使用double类型): 2.素数值的字符串表示”Prime=nnn“,其中数字 ...

  2. Feature Scaling

    定义:Feature scaling is a method used to standardize the range of independent variables or features of ...

  3. MVC 学习系列-Controller

    MVC最核心的也就是Controller了,控制器(controller)在功能中起到了核心功能. 1,)在MVC类库中,根据URL,通过MVCHandler进入MVC处理系统中, 2,)解析初始化对 ...

  4. MJRefresh简单处理

    //下拉刷新 默认 self.bottomTableVeiw.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [self he ...

  5. PostgreSQL Replication之第十一章 使用Skytools(3)

    11.3 管理 pgq-queues Skytools 的一个核心组件是pgq.它提供了一个通用排队接口,它可以让您把消息从一个消息提供者传送到一个任意数目的接收者. 现在的问题是:一般来说,一个队列 ...

  6. HUD 5086 Revenge of Segment Tree(递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5086 题目大意: 给定一个序列,求这个序列的子序列的和,再求所有子序列总和,这些子序列是连续的.去题目给的第二组 ...

  7. 序列变换(hdu5248)

    序列变换 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. csuoj 1396: Erase Securely

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1396 1396: Erase Securely Time Limit: 1 Sec  Memory ...

  9. Python学习总结17:exec和eval执行求值字符串

    有些时候可能会需要动态地创造Python代码,然后将其作为语句执行或作为表达式计算. 1. exec >>>exec "print 'Hello, world!'" ...

  10. poj: 3094

    简单题 #include <iostream> #include <stdio.h> #include <string> #include <stack> ...