在android系统对话框内自定义的ListView [英] Custom ListView inside a dialog in android

查看:173
本文介绍了在android系统对话框内自定义的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图与列表视图中的自定义对话框,也会包含复选框和textviews,我只是无法找到一个合理的教程去做,任何帮助或提示将AP preciated。


解决方案

 私人无效showPopUp()
{
    最后AlertDialog.Builder helpBuilder =新AlertDialog.Builder(本);
    helpBuilder.setTitle();    LayoutInflater吹气= getLayoutInflater();
    最后查看PopupLayout = inflater.inflate(R.layout.yourxml,NULL);
    helpBuilder.setView(PopupLayout);    最终AlertDialog helpDialog = helpBuilder.create();
    helpDialog.show();    招贤纳才=(ListView控件)PopupLayout.findViewById(R.id.list);    MYLIST =新的ArrayList<&HashMap的LT;字符串,字符串>>();    的for(int i = 0; I< arraylist.size();我++)
    {
        地图=新的HashMap<字符串,字符串>();
        map.put(名,arraylist.get(I));
        mylist.add(地图);
    }
    SD =新SimpleAdapter(activity.this,MYLIST,R.layout.jobslist,
                新的String [] {名},新的INT [] {R.id.jobText});
    jobList.setAdapter(SD);
}

joblist.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID / lin01
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=#FFF
机器人:填充=10dp
机器人:方向=横向>        <的TextView
            机器人:ID =@ + ID / jobText
            机器人:layout_width =0dp
            机器人:文字=@字符串/ jobtype
            机器人:layout_weight =1
            机器人:重力=左| center_vertical
            机器人:layout_marginLeft =10dp
            机器人:TEXTSIZE =25dp
            机器人:文字颜色=#000
            机器人:layout_height =50dp/>        <复选框
            机器人:ID =@ + ID / CHK
            机器人:layout_width =WRAP_CONTENT
            机器人:文字=
            机器人:重力=center_vertical |权
            机器人:layout_height =WRAP_CONTENT/>
        < / LinearLayout中>

无论你想要显示的列表视图与警报对话框函数;

您可以调用这个 showPopUp()。请注意,会有您可以将项目添加到它显示在列表中的项目该ArrayList

I am trying to make a custom dialog with listview which is going to contain checkboxes and textviews and i just couldnt find a reasonable tutorial to do it , any help or hints would be appreciated.

解决方案

private void showPopUp()
{
    final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
    helpBuilder.setTitle("");

    LayoutInflater inflater = getLayoutInflater();
    final View PopupLayout = inflater.inflate(R.layout.yourxml, null);
    helpBuilder.setView(PopupLayout);

    final AlertDialog helpDialog = helpBuilder.create();
    helpDialog.show();

    jobList         =   (ListView)PopupLayout.findViewById(R.id.list);

    mylist          =   new ArrayList<HashMap<String, String>>();

    for(int i=0;i<arraylist.size();i++)
    {
        map = new HashMap<String, String>();
        map.put("name", arraylist.get(i));
        mylist.add(map);
    }
    sd = new SimpleAdapter(activity.this,mylist,R.layout.jobslist,
                new String[]{"name"},new int[]{R.id.jobText});
    jobList.setAdapter(sd);


}

joblist.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/lin01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="10dp"
android:orientation="horizontal">

        <TextView
            android:id="@+id/jobText"
            android:layout_width="0dp"
            android:text="@string/jobtype"
            android:layout_weight="1"
            android:gravity="left|center_vertical"
            android:layout_marginLeft="10dp"
            android:textSize="25dp"
            android:textColor="#000"
            android:layout_height="50dp"/>

        <CheckBox 
            android:id="@+id/chk"
            android:layout_width="wrap_content"
            android:text=""
            android:gravity="center_vertical|right"
            android:layout_height="wrap_content"/>


        </LinearLayout>

you can call this showPopUp(); function wherever you want to display the alert dialog with listview. please note that there will be the arraylist which you can add items to it to show the items in a list

这篇关于在android系统对话框内自定义的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆