adding style dinamically to a TextView

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


Sponsored Links
 Hello

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)
this.findViewById(R.id.itemText);

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

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

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.

Thanks

--



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 (GolfCaddie.java) which in turn calls another 
class file called DBHelper.java.
DBHelper.java will open the my DB and will also create all the necessary 
tables if the onCreate is triggered.


Here is the code for DBHelper.java.  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 GolfCaddie.java file and it works fine there.


package com.dtwconsulting.golfcaddietrial;

import android.app.Activity;
import android.app.ProgressDialog;
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) {
        super.onCreate(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);
        }

        @Override
        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 = ProgressDialog.show(DBHelper.this, "",
                    "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){
                db.execSQL(sql);
            }
           dialog.dismiss();

        }

    }

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

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

    public void close() {
        dbHelper.close();
    }
}

--
------------------------------------------------------------------------

David Williams
Check out our WebOS mobile phone app for the Palm Pre and Pixi:
<http://www.dtw-consulting.com/GolfCaddie> Golf Caddie 
<http://www.dtw-consulting.com/GolfCaddie> | Golf Caddie Forum 
<http://www.dtw-consulting.com/GolfCaddie/forum> | Golf Caddie FAQ 
<http://www.dtw-consulting.com/GolfCaddie/faq.html> by DTW-Consulting, Inc.



--

<<inline: GClogo.png>>

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

Hi,

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