SHOW:
|
|
- or go back to the newest paste.
| 1 | Activity Main (XML) | |
| 2 | -------------------- | |
| 3 | ||
| 4 | <?xml version="1.0" encoding="utf-8"?> | |
| 5 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 6 | xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 7 | xmlns:tools="http://schemas.android.com/tools" | |
| 8 | android:layout_width="match_parent" | |
| 9 | android:layout_height="match_parent" | |
| 10 | android:orientation="vertical" | |
| 11 | tools:context="com.example.user.listwithfonts.MainActivity" | |
| 12 | android:weightSum="1"> | |
| 13 | ||
| 14 | <EditText | |
| 15 | android:id="@+id/etext" | |
| 16 | android:layout_width="match_parent" | |
| 17 | android:layout_height="wrap_content" | |
| 18 | android:hint="Your text here" | |
| 19 | android:gravity="center" | |
| 20 | android:textSize="50sp" | |
| 21 | android:layout_marginBottom="50dp" | |
| 22 | android:layout_marginLeft="15dp" | |
| 23 | android:layout_marginRight="15dp"/> | |
| 24 | ||
| 25 | <ListView | |
| 26 | android:id="@+id/list" | |
| 27 | android:layout_width="match_parent" | |
| 28 | android:layout_height="wrap_content"> | |
| 29 | </ListView> | |
| 30 | ||
| 31 | </LinearLayout> | |
| 32 | ||
| 33 | ========================================================================== | |
| 34 | ||
| 35 | ||
| 36 | MainActivity (java) | |
| 37 | ----------------------- | |
| 38 | ||
| 39 | package com.example.user.listwithfonts; | |
| 40 | ||
| 41 | import android.graphics.Typeface; | |
| 42 | import android.support.v7.app.AppCompatActivity; | |
| 43 | import android.os.Bundle; | |
| 44 | import android.view.View; | |
| 45 | import android.widget.AdapterView; | |
| 46 | import android.widget.ArrayAdapter; | |
| 47 | import android.widget.EditText; | |
| 48 | import android.widget.ListView; | |
| 49 | ||
| 50 | public class MainActivity extends AppCompatActivity {
| |
| 51 | ||
| 52 | ListView mylist; | |
| 53 | EditText mytext; | |
| 54 | ||
| 55 | @Override | |
| 56 | protected void onCreate(Bundle savedInstanceState) {
| |
| 57 | super.onCreate(savedInstanceState); | |
| 58 | setContentView(R.layout.activity_main); | |
| 59 | ||
| 60 | mylist = (ListView) findViewById(R.id.list); | |
| 61 | mytext = (EditText) findViewById(R.id.etext); | |
| 62 | ||
| 63 | String[] values = new String[] {"AngillaTattoo","Cantate Beveled","KrinkesDecorPERSONAL","KrinkesRegularPERSONAL","Silent Reaction"};
| |
| 64 | ||
| 65 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,values); | |
| 66 | mylist.setAdapter(adapter); | |
| 67 | ||
| 68 | mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
| |
| 69 | @Override | |
| 70 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
| |
| 71 | ||
| 72 | String itemValue = (String) mylist.getItemAtPosition(position); | |
| 73 | if(itemValue.equals("AngillaTattoo"))
| |
| 74 | {
| |
| 75 | mytext.setText(mytext.getText().toString()); | |
| 76 | String fontPath="fonts/AngillaTattoo.ttf"; | |
| 77 | Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); | |
| 78 | mytext.setTypeface(tf); | |
| 79 | } | |
| 80 | ||
| 81 | if(itemValue.equals("Cantate Beveled"))
| |
| 82 | {
| |
| 83 | mytext.setText(mytext.getText().toString()); | |
| 84 | String fontPath="fonts/Cantate Beveled.ttf"; | |
| 85 | Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); | |
| 86 | mytext.setTypeface(tf); | |
| 87 | } | |
| 88 | ||
| 89 | if(itemValue.equals("KrinkesDecorPERSONAL"))
| |
| 90 | {
| |
| 91 | mytext.setText(mytext.getText().toString()); | |
| 92 | String fontPath="fonts/KrinkesDecorPERSONAL.ttf"; | |
| 93 | Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); | |
| 94 | mytext.setTypeface(tf); | |
| 95 | } | |
| 96 | ||
| 97 | if(itemValue.equals("KrinkesRegularPERSONAL"))
| |
| 98 | {
| |
| 99 | mytext.setText(mytext.getText().toString()); | |
| 100 | String fontPath="fonts/KrinkesRegularPERSONAL.ttf"; | |
| 101 | Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); | |
| 102 | mytext.setTypeface(tf); | |
| 103 | } | |
| 104 | ||
| 105 | if(itemValue.equals("Silent Reaction"))
| |
| 106 | {
| |
| 107 | mytext.setText(mytext.getText().toString()); | |
| 108 | String fontPath="fonts/Silent Reaction.ttf"; | |
| 109 | Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); | |
| 110 | mytext.setTypeface(tf); | |
| 111 | } | |
| 112 | } | |
| 113 | }); | |
| 114 | ||
| 115 | ||
| 116 | ||
| 117 | ||
| 118 | ||
| 119 | } | |
| 120 | } | |
| 121 | ||
| 122 | ||
| 123 | ========================================================================= |