Anjali
Anjali

Reputation: 1691

Change font size of listview using seek bar in android

I want to change font size of list view.

I have an activity which is dervied from ActionBarActivity. In this activity there is one list view and one cursoradapter. To set the adapter i use setlistadapter method. In adapter i have overriden newview and bindview methods.

below is the code for adapter.

public EncCursorAdapter( final Context context, final Cursor c )
{
    super( context, c, false);
    // Cache the LayoutInflate to avoid asking for a new one each time.
    mInflater = LayoutInflater.from(context);
}

@Override
public void bindView( final View view, final Context context, final Cursor cursor )
{
    ( ( TextView ) view.findViewById( R.id.tvTerm ) ).setText( cursor.getString( cursor
            .getColumnIndex( EncDbAdapter.KEY_TERM ) ) );
    ( ( TextView ) view.findViewById( R.id.tvSynopsis ) ).setText( cursor.getString(
            cursor.getColumnIndex( EncDbAdapter.KEY_DISPDEF ) ).replaceAll( "\r\n", "" ) );
}

@Override
public View newView( final Context context, final Cursor cursor, final ViewGroup parent )
{
    final View newView = mInflater.inflate(R.layout.definition_row, parent, false );
    //bindView( newView, context, cursor );
    return newView;
}

i have 2 textview for the listview. where 1 is for the term and another for synopsis.

Below is activity code

public class Browse extends ActionBarListActivity{
 private static ListView lCurrentList = null;
 EncCursorAdapter eca;
  @Override
public void onCreate( final Bundle savedInstanceState )
{
 lCurrentList = (ListView) findViewById( android.R.id.list );
 eca = new EncCursorAdapter( this, null );
}

 private void setListToCursor( Cursor x )
 {      
    mTermsCursor = new DebugCursor(x);

    //startManagingCursor( mTermsCursor );
    eca.changeCursor( mTermsCursor );
    setListAdapter( eca );
 }

Above code is not complete code...just for the reference. I am already using seekbar to change fontsize of webview contents. but not getting how to do same for listview. Please help me to change the fontsize of the listview using seekbar.

Thanks in advance.....

Upvotes: 0

Views: 567

Answers (1)

Nagaraju V
Nagaraju V

Reputation: 2757

In your adapter take one variable for storing size as follows

int size=15; //give how much you want

Next take one more method in adapter to set size from outside with adapter reference

public void setSize(int size){

  this.size=size;

}

In bindview() of Adapter

( ( TextView ) view.findViewById( R.id.tvTerm ) ).setTextSize(size);

If you use seekbar in onSeekBarChangeListener() read seekBar value and call

adapter.setSize(size);
adapter.notifyDatasetChanged(); or adapter.changeCursor(-);

hope this will helps you.

Upvotes: 1

Related Questions