1 Replies - 427 Views - Last Post: 10 September 2017 - 09:28 AM

#1 suhailpappu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 02-July 17

i am trying to create a Font Changer app with spinner

Posted 10 September 2017 - 07:06 AM

I am all new to this app stuff and i am not getting the expected output. The expected output is when user enters some text he can select his desired font in drop down menu and when clicked the button it should display the input text with desired font as text view. I think i am missing somewhere between edit text,button and spinner. i first tried with just one edit text and a button and thought to get this to the next step by adding a drop down .But I seem I am unable to do this. Please help me to solve this..thank you.


package com.pappu5.fontchanger;

import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

Spinner sp ;
String names[] = {"Chiller Regular","Magneto Bold","Old English","FixedSys Regular","Rosewood"};

String record = "";
ArrayAdapter<String> adapter;

TextView tv;

protected void onCreate(Bundle savedInstanceState) {


    sp = (Spinner)findViewById(R.id.spinner);
    final EditText ed = (EditText)findViewById(R.id.editText);
    final Button bt = (Button)findViewById(R.id.button);

    tv = (TextView)findViewById(R.id.pappuText);
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,names);

    sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {

            //String item = adapterView.getItemAtPosition(position).toString();
            switch (position){
                case 0 :
                     record = String.valueOf(ed.getText());

        public void onNothingSelected(AdapterView<?> adapterView) {


    bt.setonclickListener(new View.onclickListener() {
        public void onclick(View view) {
public void selectFont(String pos){
    Typeface tf = Typeface.createFromAsset(getAssets(),"GOUDYSTO.TTF");
    Typeface tf1 = Typeface.createFromAsset(getAssets(),"MAGNETOB.TTF");
    Typeface tf2 = Typeface.createFromAsset(getAssets(),"OLDENGL.TTF");
    Typeface tf3 = Typeface.createFromAsset(getAssets(),"CHILLER.TTF");

    if(pos=="Chiller Regular"){
    }else if (pos=="Magneto Bold"){
    }else if (pos=="OLD ENGLISH"){
    }else if(pos=="ROSEWOOD"){

Is This A Good Question/Topic? 0
  • +

Replies To: i am trying to create a Font Changer app with spinner

#2 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 850
  • View blog
  • Posts: 3,413
  • Joined: 13-June 14

Re: i am trying to create a Font Changer app with spinner

Posted 10 September 2017 - 09:28 AM

Lines 71-79: you're comparing strings with ==. This is incorrect in Java; you should be using the equals method to compare identity.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1