DialogFragment下面的ListView额外的空间 [英] DialogFragment with extra space below ListView

查看:411
本文介绍了DialogFragment下面的ListView额外的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如你所看到的,在我的ListView底部列表元素的下面,有多余的空间,我似乎无法摆脱的。我试过相对和LinearLayout中,无论是这个样子。这里的code:

 公共类ChooseDialog扩展DialogFragment工具
        DialogInterface.OnClickListener {

    字符串URLhome;
    字符串名称;
    字符型;

/ *公共静态ChooseDialog的newInstance(){
        ChooseDialog对话框=新ChooseDialog();
        Log.v(A,狗屎运行);
        束束=新包();
        dialog.setArguments(包);
        返回对话框;
    } * /

    公共ChooseDialog(字符串类型){
        this.type =类型;
    }

    @覆盖
    公共无效的onCreate(束捆){
        super.onCreate(包);
        setCancelable(真正的);
        INT风格= DialogFragment.STYLE_NORMAL,主题= 0;
        的setStyle(风格,主题);
    }

     @覆盖
        公共对话onCreateDialog(包savedInstanceState){
            AlertDialog.Builder建设者=新AlertDialog.Builder(getActivity());
            builder.setTitle(类型);
            builder.setNegativeButton(取消,这一点);
            LayoutInflater充气=(LayoutInflater)getActivity()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。
            查看dialogLayout = inflater.inflate(R.layout.dialog,NULL);
            builder.setView(dialogLayout);

            最终的String []项目= {红,绿,蓝};

            builder.setAdapter(新ArrayAdapter<字符串>(getActivity(),android.R.layout.simple_list_item_1,物品),
                    新DialogInterface.OnClickListener(){


                公共无效的onClick(DialogInterface对话,诠释它){
                    Log.v(感动,项目[它]的ToString());

                }}
                );


            返回builder.create();

        }

    @覆盖
    公共无效的onClick(DialogInterface对话,诠释它){
        // TODO自动生成方法存根

    }

}
 

而code,它启动的对话框:

 公共OnClickListener监听器=新OnClickListener(){
    公共无效的onClick(视图v){
        showNationalityDialog();
    }
};

私人无效showNationalityDialog(){
    FragmentManager FM = getSupportFragmentManager();
    ChooseDialog nationalityDialog =新ChooseDialog(国籍);

    nationalityDialog.show(FM,fragment_edit_name);
}
 

解决方案

我知道这个问题从来没有吸引太多的关注,但我终于解决了这个问题。

使用我的XML创建,而不是设置建设者的适配器列表视图,我设法摆脱所有多余的空间。

下面就是新的code是这样的:

 开关(editText.getId()){
    情况下(0):
    ListView控件列表=(ListView控件)dialogLayout.findViewById(R.id.listView1);
    list.setAdapter(新ArrayAdapter<字符串>(活动,R.layout.dialoglist,
            。activity.getResources()getStringArray(R.array.ageArray)));
    list.setOnItemClickListener(新OnItemClickListener(){
        公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT ARG2,
                长ARG3){
            editText.setText(activity.getResources()getStringArray(R.array.ageArray)[ARG2]);
            解雇();
        }
    });
    建设者=(的Integer.parseInt(android.os.Build.VERSION.SDK)< 11)?新AlertDialog.Builder(活动):
        新AlertDialog.Builder(活动,android.R.style.Theme_Translucent);
    builder.setNegativeButton(取消,这一点);
    builder.setView(dialogLayout);

    返回builder.create();
 

As you can see, below the bottom list element in my ListView, there is excess space I can't seem to be rid of. I've tried Relative and Linearlayout, both look like this. Here's the code:

public class ChooseDialog extends DialogFragment implements
        DialogInterface.OnClickListener {

    String URLhome;
    String Title;
    String type;

/*  public static ChooseDialog newInstance() {
        ChooseDialog dialog = new ChooseDialog();
        Log.v("a", "shit runs");
        Bundle bundle = new Bundle();
        dialog.setArguments(bundle);
        return dialog;
    }*/

    public ChooseDialog(String type) {
        this.type = type;
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setCancelable(true);
        int style = DialogFragment.STYLE_NORMAL, theme = 0;
        setStyle(style, theme);
    }

     @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(type);
            builder.setNegativeButton("Cancel", this);
            LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View dialogLayout = inflater.inflate(R.layout.dialog, null);
            builder.setView(dialogLayout);

            final String[] items = {"Red", "Green", "Blue" };

            builder.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items), 
                    new DialogInterface.OnClickListener() {


                public void onClick(DialogInterface dialog, int which) {
                    Log.v("touched: ", items[which].toString());

                }} 
                );


            return builder.create();

        }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub

    }

}

And the code that launches the dialog:

public OnClickListener listener = new OnClickListener() {
    public void onClick(View v) {
        showNationalityDialog();
    }
};

private void showNationalityDialog() {
    FragmentManager fm = getSupportFragmentManager();
    ChooseDialog nationalityDialog = new ChooseDialog("Nationality");

    nationalityDialog.show(fm, "fragment_edit_name");
}

解决方案

I know this question never drew much attention, but I finally solved the problem.

By using the listview that I created in XML rather than setting the builder's adapter, I managed to get rid of all the excess space.

Here's what the new code looks like:

    switch (editText.getId()) {
    case (0) :
    ListView list = (ListView) dialogLayout.findViewById(R.id.listView1);
    list.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist, 
            activity.getResources().getStringArray(R.array.ageArray)));
    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            editText.setText(activity.getResources().getStringArray(R.array.ageArray)[arg2]);
            dismiss();
        }   
    });
    builder = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new AlertDialog.Builder(activity) : 
        new AlertDialog.Builder(activity, android.R.style.Theme_Translucent);
    builder.setNegativeButton("Cancel", this);
    builder.setView(dialogLayout);

    return builder.create();

这篇关于DialogFragment下面的ListView额外的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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