Android的AlertDialog详解(7种方式)

article/2025/10/31 19:07:30

需要注意的两点:

1. 在setIcon时,需要使用setTitle方法,否则icon不会显示

2.如果同时调用setMessage 和 setItems(或者setSingleChoiceItems setMultiChoiceItems)函数会导致dialog没有显示内容

============================================================

AlertDialog的构造方法全部是Protected的,所以不能直接通过new一个AlertDialog来创建出一个AlertDialog。

要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法。

使用AlertDialog.Builder创建对话框需要了解以下几个方法:

setTitle :为对话框设置标题
setIcon :为对话框设置图标
setMessage:为对话框设置内容
setView : 给对话框设置自定义样式
setItems :设置对话框要显示的一个list,一般用于显示几个命令时
setMultiChoiceItems :用来设置对话框显示一系列的复选框
setNeutralButton    :普通按钮

setPositiveButton   :给对话框添加"Yes"按钮
setNegativeButton :对话框添加"No"按钮
create : 创建对话框
show :显示对话框
一、简单的AlertDialog

下面,创建一个简单的ALertDialog并显示它:


[java]  package com.tianjf; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.os.Bundle; 
 
public class Dialog_AlertDialogDemoActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
        Dialog alertDialog = new AlertDialog.Builder(this). 
                setTitle("对话框的标题"). 
                setMessage("对话框的内容"). 
                setIcon(R.drawable.ic_launcher). 
                create(); 
        alertDialog.show(); 
    } 

package com.tianjf;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;

public class Dialog_AlertDialogDemoActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  Dialog alertDialog = new AlertDialog.Builder(this).
    setTitle("对话框的标题").
    setMessage("对话框的内容").
    setIcon(R.drawable.ic_launcher).
    create();
  alertDialog.show();
 }
}运行结果如下:

 

\


二、带按钮的AlertDialog

上面的例子很简单,下面我们在这个AlertDialog上面加几个Button,实现删除操作的提示对话框


[java] package com.tianjf; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.os.Bundle; 
 
public class Dialog_AlertDialogDemoActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
        Dialog alertDialog = new AlertDialog.Builder(this). 
                setTitle("确定删除?"). 
                setMessage("您确定删除该条信息吗?"). 
                setIcon(R.drawable.ic_launcher). 
                setPositiveButton("确定", new DialogInterface.OnClickListener() { 
                     
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                setNegativeButton("取消", new DialogInterface.OnClickListener() { 
                     
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                setNeutralButton("查看详情", new DialogInterface.OnClickListener() { 
                     
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                create(); 
        alertDialog.show(); 
    } 

package com.tianjf;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class Dialog_AlertDialogDemoActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  Dialog alertDialog = new AlertDialog.Builder(this).
    setTitle("确定删除?").
    setMessage("您确定删除该条信息吗?").
    setIcon(R.drawable.ic_launcher).
    setPositiveButton("确定", new DialogInterface.OnClickListener() {
     
     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    setNegativeButton("取消", new DialogInterface.OnClickListener() {
     
     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    setNeutralButton("查看详情", new DialogInterface.OnClickListener() {
     
     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    create();
  alertDialog.show();
 }
}在这个例子中,我们定义了三个按钮,分别是"Yes"按钮,"No"按钮以及一个普通按钮,每个按钮都有onClick事件,TODO的地方可以放点了按钮之后想要做的一些处理

看一下运行结果:

 

\


可以看到三个按钮添加到了AlertDialog上,三个没有添加事件处理的按钮,点了只是关闭对话框,没有任何其他操作。

三、类似ListView的AlertDialog
用setItems(CharSequence[] items, final OnClickListener listener)方法来实现类似ListView的AlertDialog

第一个参数是要显示的数据的数组,第二个参数是点击某个item的触发事件


[java] package com.tianjf; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.os.Bundle; 
import android.widget.Toast; 
 
public class Dialog_AlertDialogDemoActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
        final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" }; 
 
        Dialog alertDialog = new AlertDialog.Builder(this). 
                setTitle("你喜欢吃哪种水果?"). 
                setIcon(R.drawable.ic_launcher) 
                .setItems(arrayFruit, new DialogInterface.OnClickListener() { 
  
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        Toast.makeText(Dialog_AlertDialogDemoActivity.this, arrayFruit[which], Toast.LENGTH_SHORT).show(); 
                    } 
                }). 
                setNegativeButton("取消", new DialogInterface.OnClickListener() { 
 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                create(); 
        alertDialog.show(); 
    } 

package com.tianjf;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

public class Dialog_AlertDialogDemoActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };

  Dialog alertDialog = new AlertDialog.Builder(this).
    setTitle("你喜欢吃哪种水果?").
    setIcon(R.drawable.ic_launcher)
    .setItems(arrayFruit, new DialogInterface.OnClickListener() {
 
     @Override
     public void onClick(DialogInterface dialog, int which) {
      Toast.makeText(Dialog_AlertDialogDemoActivity.this, arrayFruit[which], Toast.LENGTH_SHORT).show();
     }
    }).
    setNegativeButton("取消", new DialogInterface.OnClickListener() {

     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    create();
  alertDialog.show();
 }
}运行结果如下:

 

\

四、类似RadioButton的AlertDialog
用setSingleChoiceItems(CharSequence[] items, int checkedItem, final OnClickListener listener)方法来实现类似RadioButton的AlertDialog

第一个参数是要显示的数据的数组,第二个参数是初始值(初始被选中的item),第三个参数是点击某个item的触发事件

在这个例子里面我们设了一个selectedFruitIndex用来记住选中的item的index


[java] package com.tianjf; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.os.Bundle; 
import android.widget.Toast; 
 
public class Dialog_AlertDialogDemoActivity extends Activity { 
     
    private int selectedFruitIndex = 0; 
     
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
        final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" }; 
 
        Dialog alertDialog = new AlertDialog.Builder(this). 
                setTitle("你喜欢吃哪种水果?"). 
                setIcon(R.drawable.ic_launcher) 
                .setSingleChoiceItems(arrayFruit, 0, new DialogInterface.OnClickListener() { 
  
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        selectedFruitIndex = which; 
                    } 
                }). 
                setPositiveButton("确认", new DialogInterface.OnClickListener() { 
 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        Toast.makeText(Dialog_AlertDialogDemoActivity.this, arrayFruit[selectedFruitIndex], Toast.LENGTH_SHORT).show(); 
                    } 
                }). 
                setNegativeButton("取消", new DialogInterface.OnClickListener() { 
 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                create(); 
        alertDialog.show(); 
    } 

package com.tianjf;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

public class Dialog_AlertDialogDemoActivity extends Activity {
 
 private int selectedFruitIndex = 0;
 
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };

  Dialog alertDialog = new AlertDialog.Builder(this).
    setTitle("你喜欢吃哪种水果?").
    setIcon(R.drawable.ic_launcher)
    .setSingleChoiceItems(arrayFruit, 0, new DialogInterface.OnClickListener() {
 
     @Override
     public void onClick(DialogInterface dialog, int which) {
      selectedFruitIndex = which;
     }
    }).
    setPositiveButton("确认", new DialogInterface.OnClickListener() {

     @Override
     public void onClick(DialogInterface dialog, int which) {
      Toast.makeText(Dialog_AlertDialogDemoActivity.this, arrayFruit[selectedFruitIndex], Toast.LENGTH_SHORT).show();
     }
    }).
    setNegativeButton("取消", new DialogInterface.OnClickListener() {

     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    create();
  alertDialog.show();
 }
}

运行结果如下:

 

\


五、类似CheckBox的AlertDialog
用setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, final OnMultiChoiceClickListener listener)方法来实现类似CheckBox的AlertDialog
第一个参数是要显示的数据的数组,第二个参数是选中状态的数组,第三个参数是点击某个item的触发事件


[java] package com.tianjf; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.os.Bundle; 
import android.widget.Toast; 
 
public class Dialog_AlertDialogDemoActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
        final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" }; 
        final boolean[] arrayFruitSelected = new boolean[] {true, true, false, false}; 
 
        Dialog alertDialog = new AlertDialog.Builder(this). 
                setTitle("你喜欢吃哪种水果?"). 
                setIcon(R.drawable.ic_launcher) 
                .setMultiChoiceItems(arrayFruit, arrayFruitSelected, new DialogInterface.OnMultiChoiceClickListener() { 
                     
                    @Override 
                    public void onClick(DialogInterface dialog, int which, boolean isChecked) { 
                        arrayFruitSelected[which] = isChecked; 
                    } 
                }). 
                setPositiveButton("确认", new DialogInterface.OnClickListener() { 
 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        StringBuilder stringBuilder = new StringBuilder(); 
                        for (int i = 0; i < arrayFruitSelected.length; i++) { 
                            if (arrayFruitSelected[i] == true) 
                            { 
                                stringBuilder.append(arrayFruit[i] + "、"); 
                            } 
                        } 
                        Toast.makeText(Dialog_AlertDialogDemoActivity.this, stringBuilder.toString(), Toast.LENGTH_SHORT).show(); 
                    } 
                }). 
                setNegativeButton("取消", new DialogInterface.OnClickListener() { 
 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                create(); 
        alertDialog.show(); 
    } 

package com.tianjf;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

public class Dialog_AlertDialogDemoActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };
  final boolean[] arrayFruitSelected = new boolean[] {true, true, false, false};

  Dialog alertDialog = new AlertDialog.Builder(this).
    setTitle("你喜欢吃哪种水果?").
    setIcon(R.drawable.ic_launcher)
    .setMultiChoiceItems(arrayFruit, arrayFruitSelected, new DialogInterface.OnMultiChoiceClickListener() {
     
     @Override
     public void onClick(DialogInterface dialog, int which, boolean isChecked) {
      arrayFruitSelected[which] = isChecked;
     }
    }).
    setPositiveButton("确认", new DialogInterface.OnClickListener() {

     @Override
     public void onClick(DialogInterface dialog, int which) {
      StringBuilder stringBuilder = new StringBuilder();
      for (int i = 0; i < arrayFruitSelected.length; i++) {
       if (arrayFruitSelected[i] == true)
       {
        stringBuilder.append(arrayFruit[i] + "、");
       }
      }
      Toast.makeText(Dialog_AlertDialogDemoActivity.this, stringBuilder.toString(), Toast.LENGTH_SHORT).show();
     }
    }).
    setNegativeButton("取消", new DialogInterface.OnClickListener() {

     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    create();
  alertDialog.show();
 }
}运行结果如下:

 

\

六、自定义View的AlertDialog
有时候我们不能满足系统自带的AlertDialog风格,就比如说我们要实现一个Login画面,有用户名和密码,这时我们就要用到自定义View的AlertDialog

先创建Login画面的布局文件

[html] <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
 
    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" > 
 
        <TextView 
            android:layout_width="0dip" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" 
            android:text="@string/user" /> 
 
        <EditText 
            android:layout_width="0dip" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" /> 
    </LinearLayout> 
 
    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" > 
 
        <TextView 
            android:layout_width="0dip" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" 
            android:text="@string/passward" /> 
 
        <EditText 
            android:layout_width="0dip" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" /> 
    </LinearLayout> 
 
</LinearLayout> 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/user" />

        <EditText
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/passward" />

        <EditText
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>
然后在Activity里面把Login画面的布局文件添加到AlertDialog上

[java] package com.tianjf; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
 
public class Dialog_AlertDialogDemoActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
        // 取得自定义View  
        LayoutInflater layoutInflater = LayoutInflater.from(this); 
        View myLoginView = layoutInflater.inflate(R.layout.login, null); 
         
        Dialog alertDialog = new AlertDialog.Builder(this). 
                setTitle("用户登录"). 
                setIcon(R.drawable.ic_launcher). 
                setView(myLoginView). 
                setPositiveButton("登录", new DialogInterface.OnClickListener() { 
 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                setNegativeButton("取消", new DialogInterface.OnClickListener() { 
 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                }). 
                create(); 
        alertDialog.show(); 
    } 

package com.tianjf;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class Dialog_AlertDialogDemoActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  // 取得自定义View
  LayoutInflater layoutInflater = LayoutInflater.from(this);
  View myLoginView = layoutInflater.inflate(R.layout.login, null);
  
  Dialog alertDialog = new AlertDialog.Builder(this).
    setTitle("用户登录").
    setIcon(R.drawable.ic_launcher).
    setView(myLoginView).
    setPositiveButton("登录", new DialogInterface.OnClickListener() {

     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    setNegativeButton("取消", new DialogInterface.OnClickListener() {

     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).
    create();
  alertDialog.show();
 }
}运行结果如下:

 

\


http://chatgpt.dhexx.cn/article/2BYTGUW6.shtml

相关文章

AlertDialog(对话框)详解

AlertDialog可以在当前的界面上显示一个对话框&#xff0c;这个对话框是置顶于所有界面元素之上的&#xff0c;能够屏蔽掉其他控件的交互能力&#xff0c;因此AlertDialog一般是用于提示一些非常重要的内容或者警告信息。 1.创建AlertDialog 首先&#xff0c;我们来了解一下Al…

andoid小游戏开发

apk下载&#xff1a;apk下载&#xff1a;http://download.csdn.net/detail/xiangqiao123/3805861 这是去年用android写的一个小游戏&#xff0c; 我感觉不错&#xff0c;是从事android小游戏开发入门不错的案例&#xff0c; 今天就把它拿出来和大家共享一下。 程序截图&a…

android 2D 游戏的开发的方法

最近学习了android 2D 应用的开发&#xff0c;拿来和大家分享一下&#xff0c;学习2D 开发前我们先了解一下SurfaceView的使用以及贴图技术的使用&#xff0c;最后呢&#xff0c;是一个简单的2的游戏的实现。 1.SurfaceView的一些用法 提供了一个专门的绘图渲染的图形嵌入在一个…

Android手机游戏开发入门教程

Android手机游戏开发入门教程 视频欣赏地址 来自 “ ITPUB博客 ” &#xff0c;链接&#xff1a;http://blog.itpub.net/29597077/viewspace-1139520/&#xff0c;如需转载&#xff0c;请注明出处&#xff0c;否则将追究法律责任。 转载于:http://blog.itpub.net/29597077/vie…

Android 游戏开发速递

作者 / Greg Hartrell, Head of Product Management, Games on Android & Google Play 在今年 3 月举行的 Google 游戏开发者峰会上&#xff0c;我们分享了 Google 为帮助游戏开发者而持续投入研发的数种新工具和服务。这些新工具和服务能够帮助游戏开发者更轻松地查看其 A…

游戏开发相关

游戏开发—图形图像篇 游戏开发--开篇  记得我第一次玩的PC game 是KKND(绝地风暴)&#xff0c;当时的游戏平台是DOS&#xff0c;我只是觉得很好玩&#xff0c;经常和几个小学同学一起厮杀到12点。可是现在回忆起来&#xff0c;KKND无论是从智能设计还是在游戏画面与操作上都…

android小游戏制作基础,View实现游戏布局和方法

在使用android的朋友们&#xff0c;相信大家对android的游戏不陌生吧&#xff0c;像愤怒的小鸟&#xff0c;植物大战僵尸等等优秀的游戏&#xff0c;给我们带来了很好的用户体验 下面我来教大家一点android游戏开发的一点基础&#xff0c;大家可以参照这个方法框架来设计一些像…

android游戏开发的架构

&#xfeff;&#xfeff; 在编写游戏代码之前&#xff0c;必须要仔细地理顺思路&#xff0c;清晰地构建出整个游戏的框架。有的开发者经常抱怨说&#xff0c;游戏开发到最后总是千头万绪&#xff0c;一旦出现bug就不知道该如何修改&#xff0c;身心疲惫甚至是痛不欲生。其实不…

用Unity3d开发Android游戏

Unity3d是个强大的游戏引擎&#xff0c;可以很轻松的将游戏发布到Android平台上&#xff0c;今天我就来讲讲如何用Android来开发Android游戏。 首先我们要下载Android SDK&#xff0c;可以在http://developer.android.com/sdk/index.html这里下载到&#xff0c;运行installer安…

Android游戏开发的入门实例

在Android系统上开发游戏是Android开发学习者所向往的&#xff0c;有成就感也有乐趣&#xff0c;还能取得经济上的报酬。那怎样开发Android游戏呢&#xff1f;下面介绍一个简单的入门实例。 一、创建新工程   首先&#xff0c;我们在Eclipse中新建一个名为Movement的工程&…

如何开发手机游戏?

当今社会&#xff0c;手机游戏无非是当下在旅途中打发时间的最便捷的方式。有关数据显示&#xff0c;62% 的智能手机用户在购买智能手机后的一周内安装了游戏。无论你是参加聚会还是度假&#xff0c;或者周末宅在家里&#xff0c;手机都是玩游戏最方便的设备。这也正是手机游戏…

【Android游戏开发详细过程1】Android平台飞机大战游戏APP设计与实现

【Android游戏】Android平台飞机大战游戏APP设计与实现 前言一、界面设计与功能实现1.1 主界面1.2 登录界面1.2 注册界面1.4 菜单界面1.5 设置界面1.6 商店界面1.7 换机界面1.8 游戏界面1.9 欢迎界面1.10 游戏图标 二、数据库设计与实现三、服务器设计与实现四、其他功能实现 前…

datagridview中使用DataGridViewComboBoxColumn

在datagridview中使用自带的DataGridViewComboBoxColumn&#xff0c;加载数据库中的数据&#xff0c;选中和保存所需要的数据 实现效果如图 加载数据库已保存的数 选择自己所需要的数据 具体代码如下 datagridview命名为&#xff1a;dgvDrugList 添加基本列及对应的设…

DataGridView怎样实现添加、删除、上移、下移一行

场景 在Winform中使用DataGridView实现添加一行、删除一行、上移一行、下移一行。 注&#xff1a; 博客主页&#xff1a;https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书、教程推送与免费下载。 实现 添加一行 private void Task…

DataGridview获取选中行数

DataGridview获取选中行数 代码&#xff1a; dataGridView1.CurrentRow.Index//获取选中行数使用Messbox.Show()弹窗&#xff1a;

DataGridview动态初始化

DataGridview动态初始化 this.dataGridView1.Rows.Add("参数"&#xff0c;"参数"...");Add&#xff08;&#xff09;方法里面可以根据列数而添加相应个数的参数 例如&#xff1a; 上图的列数有4个&#xff0c;所以如果要将DataGridview控件里面添加…

C# 解决datagridview控件显示大量数据拖拉卡顿问题

问题描述&#xff1a; 由于在使用SQL查询大量的数据并一次显示到dataGridView控件&#xff0c;出现拖拉的时候卡顿。 解决方法&#xff1a; 1.首先分页。 2.其次把显示控件设置双buffer。 解决过程如下&#xff1a; 1.设置dataGridView双buffer代码如下&#xff0c;需要引用…

DataGridView绑定数据库

背景 今天在做C#实验的时候&#xff0c;遇到了一个难题&#xff1a;需要将数据库中的数据在C#的窗体的DataGridView控件中显示出来。当然老师布置这个作业是在之前做了铺垫的&#xff0c;之前做省县区三级查询时&#xff0c;讲过了SampleData和LiteDB的使用&#xff0c;但是我…

Winform实现在DataGridView控件的单元格中添加多个控件

Winform实现在DataGridView控件的单元格中添加多个控件 背景实现思路关键代码完整代码下载 背景 DataGridView控件的列是支持TextBoxColumn、ComboBoxColumn等类型的&#xff0c;就是DataGridView的单元格进入编辑模式的时候就会出现对应的控件&#xff0c;但是有些业务场景是…

C# datagridview 单行文字自动换行

dgv.DefaultCellStyle.WrapMode True dgv.RowTemplate.DefaultCellStyle.WrapMode True dgb.RowsDefaultCellStyle.WrapMode True dgv.AlternatingRowsDefaultCellStyle.WrapMode True 在设计界面里手动设置&#xff0c;一般情况下&#xff0c;设置其中一个WrapMode为true…