Downloadble font is not working perfect with spinner in android

+1 vote
asked Sep 13, 2017 by paras-kathiriya

Here is the adapter code using for spinner.

    public View getCustomView(final int position, View convertView, ViewGroup parent) {

        View vi = convertView;
        final ViewHolder holder;


        if (convertView == null) {
            vi = LayoutInflater.from(context).inflate(R.layout.spinner_row, null);

            holder = new ViewHolder();
            vi.setTag(holder);

        } else {
            holder = (ViewHolder) vi.getTag();
        }

        holder.textview = (TextView) vi.findViewById(R.id.textView1);
        holder.textview.setText("Your Text");
        Log.d("holder", fontfamily);
        QueryBuilder queryBuilder = new QueryBuilder(fontfamily);
        String query = queryBuilder.build();

        FontRequest request = new FontRequest(
                "com.google.android.gms.fonts",
                "com.google.android.gms",
                query,
                R.array.com_google_android_gms_fonts_certs);

        FontsContractCompat.FontRequestCallback callback = new FontsContractCompat
                .FontRequestCallback() {
            @Override
            public void onTypefaceRetrieved(Typeface typeface) {
                holder.textview.setTypeface(typeface);
                Log.d("holder", "font set for:- " + fontfamily);
            }

        };
        FontsContractCompat
                .requestFont(context, request, callback,
                        getHandlerThreadHandler());
        return vi;
    }

Issue is "'fontface' not set with respect to it's 'text'". Not sure but I think it's because of asynchronous.

Thanks is advance for help!!!

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
...