Selecting typeface from gallery and displaying in next page

14 Views Asked by At

I want to set typeface of fonts of two different types according to whether type face selected from horizontal gridview which has font types like regular etc another horizontal gridview has neon typeface font.problem is that when i select from neontype face from grid row it displays neon typeface no problem ,but when i pressed back button and selected normal fonttype but the selected font would not display as desired .Here is code

font_style_ga = (Gallery) findViewById(R.id.font_style_ga);

    font_style_ga.setAdapter(new FontStyle(this));

font_style_ga.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1,
                                int position, long arg3) {

            if (IsNativeAdVisible) {
                return;
            }
            if (position == 0) {
                externalFont = Typeface.createFromAsset(getAssets(),
                        "Creator_Campotype_smcp.otf");
            } else if (position == 1) {
                externalFont = Typeface.createFromAsset(getAssets(),
                        "Gangnam.ttf");
            } 

Similarty for neontypeface as neon_font_ga.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (IsNativeAdVisible) {
                return;
            }
            if(position==0){
                neonFonts=Typeface.createFromAsset(getAssets(),
                        "Neony_font.ttf");
            }


                NeontypeFaceName= neonTypeList[position];
                text_edt.setTextSize(textsize);
                text_edt.setTypeface(neonFonts);



        }
    });


Intent intent = new Intent(TextActivity.this,
                            FirstActivity.class);
                    intent.putExtra("text", edit_text_str);
                    intent.putExtra("textcolor", textcolor);
                    intent.putExtra("textsize", textsize);
                    intent.putExtra("typeface", typeFaceName);
                    intent.putExtra("neonTypeface",NeontypeFaceName);
                    startActivity(intent);

In firstactivity.java I am using getextra function whether typeface or NeontypeFaceName is set using if else condition as

if (bundleIntent != null) {


        adText.setText(bundleIntent.getExtras().getString("text"));


        if (bundleIntent.getExtras().getString("typeface") == null ) {

            adText.setTypeface(Typeface.DEFAULT);

        } else {

            Typeface typeFace = Typeface.createFromAsset(getAssets(),
                    bundleIntent.getExtras().getString("typeface"));

            adText.setTypeface(typeFace);

        }

        adText.setTextSize(bundleIntent.getExtras().getFloat("textsize"));

        int color = bundleIntent.getExtras().getInt("textcolor");

        if (color == 0) {

            color = Color.BLACK;
        }
        adText.setTextColor(color);


        if(bundleIntent.getExtras().getString("neonTypeface")!=null  ){
            Typeface typeFace = Typeface.createFromAsset(getAssets(),
                    bundleIntent.getExtras().getString("neonTypeface"));

            adText.setTypeface(typeFace);
            adText.setShadowLayer(11,2,-2,color);


        }else if(bundleIntent.getExtras().getString("typeface")!=null){
            Typeface typeFace = Typeface.createFromAsset(getAssets(),
                    bundleIntent.getExtras().getString("typeface"));

            adText.setTypeface(typeFace);
        }

But after pressing back and changing typeface will not get selected typeface. Please help

0

There are 0 best solutions below