adding style dinamically to a TextView

by nou » Wed, 21 Apr 2010 06:54:27 GMT

Sponsored Links

I have a String[] and I need to create a "paragraph" for each of the
strings in the array.

basically what I am doing at the moment is this:

      LinearLayout text = (LinearLayout)

      String[] ps = article.getATxt().split(Pattern.quote("\n"));

      for (String p : ps) {
         TextView newPar = new TextView(this);
         newPar.setPadding(0, 0, 0, 6);

I am not happy with the way I format (padding) each new textView beign
created. I was wondering if there is a way to assign a style
dinamically so that I can extract from the code the styling.



adding style dinamically to a TextView

by patbenatar » Wed, 21 Apr 2010 09:44:45 GMT

 This might help you:

Sponsored Links

Other Threads

1. ProgressDialog results in a FC

I have my main java class ( which in turn calls another 
class file called will open the my DB and will also create all the necessary 
tables if the onCreate is triggered.

Here is the code for  The ProgressDialog code that is in 
bold is the one that causes the FC. I know this because if I comment it 
out then everything works fine and my db tables get created.  From what 
I can tell the error is, "system services not available to activities 
before oncreate". No idea what is going on and I've used the exact same 
ProgressDialog code in my file and it works fine there.

package com.dtwconsulting.golfcaddietrial;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.util.Log;

public class DBHelper extends Activity {
    public void onCreate(Bundle savedInstanceState) {

*bunch of static constants are defined, but removed for readability.

*    private SQLiteDatabase db;
    private DatabaseHelper dbHelper;
    private final Context dbCtx;
    private static final String TAG = "DBHelper";

    private class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);

        public void onCreate(SQLiteDatabase db) {
            // If we get to this point then it means that this is the 
first time the app

            // has been run and we need to create the Golf Caddie DB.
*ProgressDialog dialog =, "",
                    "New install...setting up database",true);*

            String[] sqlStatements = new String[]{SQL1, SQL2, SQL3, 
SQL4, SQL5, SQL6, SQL7, SQL8, SQL9, SQL10, SQL11
                    , SQL12, SQL13, SQL14, SQL15, SQL16, SQL17, SQL18, 
SQL19, SQL20, SQL21, SQL22, SQL23, SQL24, SQL25, SQL26
                    , SQL27, SQL28, SQL29, SQL30, SQL31, SQL32, SQL33, 
SQL34, SQL35, SQL36, SQL37, SQL38, SQL39, SQL40, SQL41

                    , SQL42, SQL43};

            for(String sql : sqlStatements){



    public DBHelper(Context ctx) {
        this.dbCtx = ctx;

    public DBHelper open() throws SQLException {
        dbHelper = new DatabaseHelper(dbCtx);
        db = dbHelper.getWritableDatabase();
        return this;

    public void close() {


David Williams
Check out our WebOS mobile phone app for the Palm Pre and Pixi:
<> Golf Caddie 
<> | Golf Caddie Forum 
<> | Golf Caddie FAQ 
<> by DTW-Consulting, Inc.


<<inline: GClogo.png>>

2. Accessing invisible items in the list view while we scroll the list


I have eight elements in my list.

Initially only six items are visible. When I scroll down the view, the
first and second elements are not visible.

I use the getChildAt() api to get the ID of the first and second
elements for accessing them.

But I get NULL POINTER  EXCEPTION as getChildAt() returns only the
visible elements count.

How can I get the handle for the first and second elements?

Can anybody help me regarding this?

Any help would be of really great use.

Thanks in advance.

Revathi KJ


3. purgatory state in surface flinger

4. MediaMetadataRetriever.getFrameAtTime returns null frame for time = duration

5. Scaling on Two Webviews

6. Koneksi GSM for android

7. Android Proxy