I created ListView, When i click list item it will open AlertDialog Message with NegativeButton. These are worked Perfectly. Now, i want to set custom font to listview item and AlertDialog's title, message and NegativeButton's fonts. Even i tried custom font library but not getting expected output. Here am attaching my tried code below. Please can anyone tell me what's going wrong?
public class NewActivity extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
Calligrapher calligrapher = new Calligrapher(this);
calligrapher.setFont(this, "Acme-Regular.ttf", true);
listView = findViewById(R.id.list1);
final ArrayList<String> concept = new ArrayList<String>();
concept.add("Who is the captain of Indian Cricket Team?");
concept.add("When we are celebrating Teacher's Day?");
concept.add("When we are celebrating Women's Day?");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, concept);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@SuppressLint("ResourceType")
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
AlertDialog.Builder adb = new AlertDialog.Builder(NewActivity.this);
switch (i)
{
case 0:
adb.setTitle(concept.get(i));
adb.setMessage("Virat Kholi");
adb.setNegativeButton("Close", null);
adb.show();
break;
case 1:
adb.setTitle(concept.get(i));
adb.setMessage("September 5");
adb.setNegativeButton("Close", null);
adb.show();
break;
case 2:
adb.setTitle(concept.get(i));
adb.setMessage("March 8");
Typeface customTypeOne = Typeface.createFromAsset(getAssets(), "Acme-Regular.ttf");
adb.setTypeface(customTypeOne);
adb.setNegativeButton("Close", null);
adb.show();
break;
}
}
});
}
}
xml file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
tools:context=".NewActivity">
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp"
android:fontFamily="assets/Acme-Regular.ttf"
tools:ignore="MissingConstraints" />
</android.support.constraint.ConstraintLayout>