Create custom listview with text font size increase-decrease as user requirement in android.
In this tutorial we are changing the font size of each listview items by creating textview list array inside it. When we have create textview list inside listview then we can easily set font size of list view items in android. So here is the complete step by step tutorial for Change listview item text size in android programmatically.
How to Change listview item text size in android programmatically.
Code for MainActivity.java file.
package com.changelistviewitemtextsize_android_examples.com; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.view.ViewGroup; public class MainActivity extends Activity { ListView listviewFontChange; String[] listviewFontChange_Value = new String[] { "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN" }; List<String> convertString; ArrayAdapter<String> arrayadapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listviewFontChange = (ListView)findViewById(R.id.listView1); convertString = new ArrayList<String>(Arrays.asList(listviewFontChange_Value)); arrayadapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, convertString){ @Override public View getView(int position, View convertView, ViewGroup parent){ View view = super.getView(position, convertView, parent); TextView textview = (TextView) view.findViewById(android.R.id.text1); //Set your Font Size Here. textview.setTextSize(20); return view; } }; listviewFontChange.setAdapter(arrayadapter); } }
Code for activity_main.xml layout file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.changelistviewitemtextsize_android_examples.com.MainActivity" > <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> </RelativeLayout>
Screenshot: