当前位置:操作系统 > 安卓/Android >>

Android Listview对话框

MainActivity.java

[java]
package com.example.test; 
 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
 
import android.os.Bundle; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInte易做图ce; 
import android.view.Menu; 
import android.view.View; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.ListView; 
 
public class MainActivity extends Activity { 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
         
        Button btn=(Button)findViewById(R.id.button1); 
        btn.setOnClickListener(new View.OnClickListener() { 
             
            @Override 
            public void onClick(View v) { 
                // TODO Auto-generated method stub  
                List<Map<String, Object>> lst_data = new ArrayList<Map<String, Object>>(); 
 
                for(int i=0;i<20;i++){ 
                    Map<String, Object> map = new HashMap<String, Object>(); 
                    map.put("Name", "内容"+i); 
                    lst_data.add(map); 
                } 
                 
                 
                ListView lst_category = new ListView(MainActivity.this); 
                 
                DeleteCategoryAdapter adapter = new DeleteCategoryAdapter( 
                        MainActivity.this, lst_data); 
                lst_category.setAdapter(adapter); 
 
                AlertDialog alertDialog = new AlertDialog.Builder( 
                        MainActivity.this).create(); 
                alertDialog.setTitle("修改"); 
                alertDialog.setIcon(android.R.drawable.ic_dialog_info); 
                alertDialog.setView(lst_category); 
                alertDialog.setButton(Dialog.BUTTON_POSITIVE, "正确", 
                        new DialogInte易做图ce.OnClickListener() { 
 
                            @Override 
                            public void onClick(DialogInte易做图ce dialog, 
                                    int which) { 
                                // TODO Auto-generated method stub  
 
                            } 
                        }); 
                alertDialog.setButton(Dialog.BUTTON_NEGATIVE, "取消", 
                        new DialogInte易做图ce.OnClickListener() { 
 
                            @Override 
                            public void onClick(DialogInte易做图ce dialog, 
                                    int which) { 
                                // TODO Auto-generated method stub  
 
                            } 
                        }); 
                alertDialog.show(); 
                alertDialog.getWindow().clearFlags( 
         &nbs

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,