简体   繁体   English

ArrayAdapter的Android对话框自定义布局

[英]Android Dialog Custom Layout for ArrayAdapter

I have a dialog that's working fine. 我有一个工作正常的对话框。 However, I want to change the size of the text and style of the dialog. 但是,我想更改文本的大小和对话框的样式。 Is there a quick way to do it without creating a custom dialog? 有没有创建自定义对话框的快速方法? I tried to apply a theme to do it, but it only changes the title text, but not the individual elements where the text is big and the size of the dialog is too big. 我尝试应用一个主题来执行此操作,但是它只会更改标题文本,而不会更改文本较大且对话框大小太大的单个元素。 Thanks. 谢谢。

AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity());

    builderSingle.setTitle("Select Item");
    final ArrayAdapter<String> arrayAdapter = listAllItems(getActivity());

    builderSingle.setNegativeButton(
        "cancel",
        new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builderSingle.setAdapter(
        arrayAdapter,
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String strName = arrayAdapter.getItem(which);
            }
        });
    builderSingle.show();

try this one 试试这个

Listview lst_state;
TextView text_t ;
LayoutInflater inflater = mactivity.getLayoutInflater();
    View alertLayout = inflater.inflate(R.layout.listview, null);
    lst_state = (ListView) alertLayout.findViewById(R.id.listview_show_like_member_we);
    text_t = (TextView) alertLayout.findViewById(R.id.text_title);
    text_t.setText("State");
    lst_state.setAdapter(adapter_state);
    final AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setView(alertLayout);

    alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    final AlertDialog dialog = alert.create();
    lst_state.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            location_t_district.setText(arrayList_state.get(position).getStatename));
           dialog.dismiss();
        }
    });
    dialog.show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM