简体   繁体   中英

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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