At first, listview uses Android’s own simple_ list_ item_1 display simple text. Use the default attribute, and the code is as follows:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, adapterData);
listView.setAdapter(adapter);
After that, when the function is updated, you need to change the font color of item and specify the typeface. Record is customized in RES/layout/folder_ text.xml File:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/TView" android:layout_width="match_parent" android:layout_height="match_parent" android:textColor="#2d373c" android:textSize="18sp" /> </LinearLayout>
Change the code in. Java file to:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(RecordActivity.this, R.layout.record_text, adapterData); listView.setAdapter(adapter); //Change the item display text to a custom font LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.record_text, null); TextView w = (TextView)view.findViewById(R.id.TView); Typeface tfsisan03 = Typeface.createFromAsset(getAssets(), "fonts/sisan03_0.ttf"); w.setTypeface (tfsisan03);
Run, error prompt: arrayadapter requires the resource ID to be a textview. Finally, we found the problem of. XML file. The root label must be textview and cannot nest LinearLayout. After modification, the error will be resolved.
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textColor="#2d373c"
android:layout_marginLeft="10dp"
android:paddingLeft="10dp"
android:gravity="center_vertical"
android:textSize="16sp"
/>
Read More:
- Flash back problem when Android studio plays music in sdcard through intent
- Android studio version 3.0 import version 2.2.2 error Error:This Gradle plugin requires Studio 3.0 minimum
- [Solved] ViewBinding Error: java.lang.ClassCastException: android.widget.RelativeLayout cannot be
- Android studio does not prompt error messages [How to Solve]
- How to Solve Android Error: gps requires ACCESS_FINE_LOCATION
- [Solved] Android Studio Start Error: Missing essential plugin: org.jetbrains.android Please reinstall Android
- [Solved] AS Warning: String literal in setText can not be translated. Use Android resources instead.
- [Solved] Android Studio 4 Error: The application could not be installed: INSTALL_FAILED_OLDER_SDK
- Android Studio: How to Solve APK error in mobile phone installation
- Android Error: Android resource linking failed [How to Solve]
- [Solved] Windows Android Studio Cannot Start Error: Internal error. Please refer to https://code.google.com/p/android/issue
- [Solved] :app:processDebugResources Android resource linking failed Android resource linking failed
- [Solved] Error response from daemon: OCI runtime create failed: container with id exists: xxzxxxxxxxx
- JZVideo Error: Attempt to invoke virtual method ‘android.view.Window android.app.Activity.getWindow()’ on a null object reference
- [Solved] Failed to apply plugin appears when Android studio imports a project
- Android Studio: Gradle project sync failed [How to Solve]
- [Solved] Android9.0 App Install Android4.4 Error: InflateException-You must supply a layout_height attribute.
- Solve the problem of incorrect display of dialogfragment width
- [Solved] Android-android studio apk Install Error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED