Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

New Forums: Nexus Player | Nexus 9
test: Reply
 
LinkBack Thread Tools
Old November 9th, 2011, 03:41 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Question how to change the color of textview

I have two xml files one is having the listview and another is having the layout of the listview vth some texviews, I want to change the color of the textview in the second xml file. This is what i have done so far.

main1.xml:

Code:
<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="4px">    
    <ListView droid:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/header"
        android:layout_above="@+id/bottom_control_bar1"
        android:layout_marginBottom="45dip"
        android:drawSelectorOnTop="false"/>
    </RelativeLayout>

opp_main.xml:


Code:
<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="8px">

    <TextView
        android:id="@+id/firstName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
        
    <TextView
        android:id="@+id/lastName"
        android:layout_marginLeft="6px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/firstName"
     />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstName"
        android:layout_toRightOf="@id/total"
        android:layout_marginLeft="8px"
        android:textColor="@color/closedDate"
        />
        </RelativeLayout>

opp.java:


Code:
public class OppMain extends ListActivity {
    /** Called when the activity is first created. */
    final String tag = "output";
    static String Header = "Opportunities";
    static String DBName, Date = null;
    protected Cursor cursor;
    protected ListAdapter adapter;
    SQLiteDatabase db;
    
    @Override
   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);
      
        TextView hdr = (TextView)findViewById(R.id.header);
        hdr.setText(Header);

        
      //database          
        
        db = (new openDataBaseAdapter(this)).getWritableDatabase();
        cursor = db.query("userdata", new String []{"_id", "Name","Name2", "Date","title"},null, null, null, null,null);
        adapter = new SimpleCursorAdapter(
                this, 
                R.layout.opp_main,  
                cursor, 
                new String[] {"Name", "Name2", "Date","title"}, 
                new int[] {R.id.firstName,R.id.total, R.id.title, R.id.accountname});
                
                cursor.moveToFirst();
                
                
                while(cursor.isAfterLast() == false)
                {
                    
                    CloseDate = cursor.getString(cursor.getColumnIndex("Date"));
                    if(CloseDate.equals("30/09/2011 00:00"))
                    {
                    
                        TextView cl = (TextView)findViewById(R.id.title);
                        Log.d(tag, "cl: " +cl);
                        Log.d(tag, "Date11111: " +Date);
                        cl.setTextColor(Color.CYAN);
                    }
                  
                    cursor.moveToNext();
                   
                   
                }
                setListAdapter(adapter);
                
       }
  

     }



I wanted to change the color of textview date which is storing in `R.id.total`.
here the log cat is giving null for the value cl.....and gives me nullpointer exception...
can any one tell me please.......?
thank you in advance...

Advertisements
rj87 is offline  
Reply With Quote
sponsored links
Old November 9th, 2011, 10:20 AM   #2 (permalink)
Senior Member
 
TheCompBoy's Avatar
 
Join Date: Oct 2010
Location: Sweden
Posts: 589
 
Device(s): Samsung Galaxy S w DarkyROM v10.1
Carrier: Not Provided

Thanks: 4
Thanked 56 Times in 51 Posts
Send a message via Skype™ to TheCompBoy
Default

Try and see if this works:

Code:
cl.setTextColor(this.getResources().getColor(R.color.orange));
__________________
Please check out my blogg: www.thecompboy.blogspot.com
If you want to support me please subscribe / follow the blogg!
TheCompBoy is offline  
Reply With Quote
Old November 10th, 2011, 02:42 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello TheCompBoy,

thank you for ur reply, I tried and it didnot work either... I printed the cl in logcat to see the id of cl but it is showing null.........
rj87 is offline  
Reply With Quote
Reply
Tags
adapterview, android 2.2, color changing, cursor, exception, listview, nullpointer, simplecursoradapter, textview


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:50 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.