Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Activity Main (XML)
- --------------------
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context="com.example.user.listwithfonts.MainActivity"
- android:weightSum="1">
- <EditText
- android:id="@+id/etext"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Your text here"
- android:gravity="center"
- android:textSize="50sp"
- android:layout_marginBottom="50dp"
- android:layout_marginLeft="15dp"
- android:layout_marginRight="15dp"/>
- <ListView
- android:id="@+id/list"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- </ListView>
- </LinearLayout>
- ==========================================================================
- MainActivity (java)
- -----------------------
- package com.example.user.listwithfonts;
- 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.EditText;
- import android.widget.ListView;
- public class MainActivity extends AppCompatActivity {
- ListView mylist;
- EditText mytext;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mylist = (ListView) findViewById(R.id.list);
- mytext = (EditText) findViewById(R.id.etext);
- String[] values = new String[] {"AngillaTattoo","Cantate Beveled","KrinkesDecorPERSONAL","KrinkesRegularPERSONAL","Silent Reaction"};
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,values);
- mylist.setAdapter(adapter);
- mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- String itemValue = (String) mylist.getItemAtPosition(position);
- if(itemValue.equals("AngillaTattoo"))
- {
- mytext.setText(mytext.getText().toString());
- String fontPath="fonts/AngillaTattoo.ttf";
- Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
- mytext.setTypeface(tf);
- }
- if(itemValue.equals("Cantate Beveled"))
- {
- mytext.setText(mytext.getText().toString());
- String fontPath="fonts/Cantate Beveled.ttf";
- Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
- mytext.setTypeface(tf);
- }
- if(itemValue.equals("KrinkesDecorPERSONAL"))
- {
- mytext.setText(mytext.getText().toString());
- String fontPath="fonts/KrinkesDecorPERSONAL.ttf";
- Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
- mytext.setTypeface(tf);
- }
- if(itemValue.equals("KrinkesRegularPERSONAL"))
- {
- mytext.setText(mytext.getText().toString());
- String fontPath="fonts/KrinkesRegularPERSONAL.ttf";
- Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
- mytext.setTypeface(tf);
- }
- if(itemValue.equals("Silent Reaction"))
- {
- mytext.setText(mytext.getText().toString());
- String fontPath="fonts/Silent Reaction.ttf";
- Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
- mytext.setTypeface(tf);
- }
- }
- });
- }
- }
- =========================================================================
Add Comment
Please, Sign In to add comment