In the application implemented a change of topics. In the ListPreference dialog box, using the adapter, added theme color selection icons. The dialog is displayed as a list. How to make it appear as a grid? Need to make a new grid view adapter or can I change an existing one? I am new to this business, I hope clearly explained the essence of the problem. This is my preferences.xml

<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <PreferenceCategory android:title="@string/change_theme"> <com.example.poweroff.IconListPreference android:defaultValue="false" android:entries="@array/pref_theme_options" android:entryValues="@array/pref_theme_values" android:icon="@mipmap/ic_theme2_round" android:key="@string/pref_theme" android:title="@string/pref_theme_title" app:ilp_entryImages="@array/IconColor" /> </PreferenceCategory> </PreferenceScreen> 

This is the iconlistpreference_item layout.

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" android:paddingStart="16dp" android:paddingLeft="16dp" android:paddingTop="8dp" android:paddingEnd="16dp" android:paddingRight="16dp" android:paddingBottom="8dp"> <ImageView android:id="@+id/iconlistpreference_image" android:layout_width="match_parent" android:layout_height="54dp" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_marginStart="3dp" android:layout_marginEnd="3dp" android:layout_marginRight="40dp" android:scaleType="centerCrop" /> <RadioButton android:id="@+id/iconlistpreference_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:layout_marginTop="11dp" android:layout_marginEnd="13dp" android:clickable="false" android:focusable="false" app:buttonTint="#ffffff" /> </RelativeLayout> <!--<TextView--> <!--android:id="@+id/imagelistpreference_text"--> <!--android:layout_width="match_parent"--> <!--android:layout_height="wrap_content"--> <!--android:layout_alignParentTop="true"--> <!--android:layout_alignParentEnd="true"--> <!--android:layout_marginStart="25dp"--> <!--android:layout_marginLeft="-149dp"--> <!--android:layout_marginTop="17dp"--> <!--android:layout_marginEnd="55dp"--> <!--android:layout_marginRight="-130dp"--> <!--android:layout_toLeftOf="@+id/imagelistpreference_image"--> <!--android:layout_toEndOf="@+id/imagelistpreference_image"--> <!--android:layout_toRightOf="@+id/imagelistpreference_radio" />--> 
This is an IconListPreference handler.

 import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.res.TypedArray; import android.preference.ListPreference; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.RadioButton; import java.util.ArrayList; import java.util.List; public class IconListPreference extends ListPreference { private static final String TAG = "IconListPreference"; private int mErrorResource; private List<Integer> mImages; private int mBackgroundColor; private boolean mUseCard; private int mCustomItemLayout; private class ImageListPreferenceAdapter extends ArrayAdapter<ImageListItem> { private List<ImageListItem> mItems; private int mLayoutResource; ImageListPreferenceAdapter(Context context, int layoutResource, List<ImageListItem> items) { super(context, layoutResource, items); mLayoutResource = layoutResource; mItems = items; } @Override public @NonNull View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { ViewHolder holder; if (convertView == null) { LayoutInflater inflater = (LayoutInflater)getContext(). getSystemService(Context.LAYOUT_INFLATER_SERVICE); try { assert inflater != null; convertView = inflater.inflate(mLayoutResource, parent, false); holder = new ViewHolder(); // holder.iconName = convertView.findViewById(R.id.imagelistpreference_text); holder.iconImage = convertView.findViewById(R.id.iconlistpreference_image); holder.radioButton = convertView.findViewById(R.id.iconlistpreference_radio); convertView.setTag(holder); } catch (Exception e) { e.printStackTrace(); return super.getView(position, null, parent); } } else { holder = (ViewHolder)convertView.getTag(); } if (holder == null) { return super.getView(position, convertView, parent); } ImageListItem item = mItems.get(position); // holder.iconName.setText(item.name); if (item.resource != 0) { holder.iconImage.setImageResource(item.resource); } else { holder.iconImage.setImageResource(mErrorResource); } if (mBackgroundColor != 0) { holder.iconImage.setBackgroundColor(mBackgroundColor); } holder.radioButton.setChecked(item.isChecked); return convertView; } } private class ImageListItem { private int resource; private boolean isChecked; private String name; ImageListItem(CharSequence name, int resource, boolean isChecked) { this(name.toString(), resource, isChecked); } ImageListItem(String name, int resource, boolean isChecked) { this.name = name; this.resource = resource; this.isChecked = isChecked; } } private class ViewHolder { ImageView iconImage; // TextView iconName; RadioButton radioButton; } public IconListPreference(Context context, AttributeSet attrs) { super(context, attrs); mImages = new ArrayList<>(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ImageListPreference); try { int entryImagesArrayResource = array.getResourceId(R.styleable.ImageListPreference_ilp_entryImages, 0); mCustomItemLayout = array.getResourceId(R.styleable.ImageListPreference_ilp_itemLayout, 0); TypedArray images = context.getResources().obtainTypedArray(entryImagesArrayResource); for (int i=0 ; i<images.length() ; i++) { mImages.add(images.getResourceId(i, 0)); } images.recycle(); } catch (Exception e) { e.printStackTrace(); } finally { array.recycle(); } } @Override protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { List<ImageListItem> items = new ArrayList<>(); int length = getEntries().length; for (int i=0 ; i<length ; i++) { int resource = 0; if (mImages.size() > i) { resource = mImages.get(i); } items.add(new ImageListItem(getEntries()[i], resource, (getEntryValues()[i]).equals(getValue()))); } int layout = R.layout.iconlistpreference_item; if (mCustomItemLayout != 0) { layout = mCustomItemLayout; } ListAdapter adapter = new ImageListPreferenceAdapter(getContext(), layout, items); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { IconListPreference.super.onClick(dialog, which); } }); super.onPrepareDialogBuilder(builder); } } 

    0