November 9th, 2011, 05:20 AM
|
#1 (permalink)
|
|
New Member
Join Date: Sep 2011
Posts: 4
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
|
How to alter the color of a textview
Hi all,
Please I have a code which is querying an SQLite database. Basically I want to alter the color of the textview which I have in an xml file with reference to the closedate
the xml code is
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/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20dip"
android:textStyle="bold"
android:textColor="#FFFFFF"
/>
<ListView
android: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"/>
<TextView
android:id="@+id/firstName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/total1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firstName"
android:textColor="@color/opp_child"/>
<TextView
android:id="@+id/title1"
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"
/>
<TextView
android:id="@+id/accountname1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/total"
android:textColor="@color/opp_child"
/>
</RelativeLayout>
and the java code is
Code:
package mCRM.android.hp;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class OppMain extends ListActivity {
/** Called when the activity is first created. */
final String tag = "output";
static String Header = "Opportunities";
static String DBName =null;
static String CloseDate =null;
int layout;
protected Cursor cursor, cursor1;
protected ListAdapter adapter, adapter1;
SQLiteDatabase db;
static String TextView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.opp_main);
TextView hdr = (TextView)findViewById(R.id.header);
hdr.setText(Header);
//home button
/*
ImageButton home = (ImageButton) findViewById(R.id.home);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(OppMain.this, Main.class);
OppMain.this.startActivity(myIntent);
}
});
//end home button
//search button
ImageButton search = (ImageButton) findViewById(R.id.search);
search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(OppMain.this,Global_search.class);
OppMain.this.startActivity(myIntent);
}
});
//end search button
//back button
ImageButton back = (ImageButton) findViewById(R.id.back);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
*/
//end back button
//database
TextView cl = (TextView)findViewById(R.layout.opp_main);
TextView cl2 = (TextView)findViewById(R.layout.opp_main1);
db = (new openDataBaseAdapter(this)).getWritableDatabase();
cursor = db.query("opportunities", new String []{"_id", "OpportunityName","SalesStageName", "CloseDate", "AccountName"}, null, null, null, null, "OpportunityName");
cursor.moveToFirst();
//CloseDate = cursor.getString(cursor.getColumnIndex("CloseDate"));
Log.d(tag, "close date:" +CloseDate);
adapter = new SimpleCursorAdapter(
this,
R.layout.opp_main,
cursor,
new String[] {"OpportunityName", "SalesStageName", "CloseDate","AccountName"},
new int[] {R.id.firstName,R.id.total, R.id.title, R.id.accountname});
int i = cursor.getCount();
Log.d(tag, "Column count " +i);
setListAdapter(adapter);
}
protected void onListItemClick(ListView lstvw, View view, int position, long id) {
// get the id and act name of position clicked and send to next intent as Emp_id and header
Intent intent = new Intent(this, Opportunities.class);
Cursor cursor = (Cursor) adapter.getItem(position);
intent.putExtra("Emp_Id", cursor.getString(cursor.getColumnIndex("_id")));
intent.putExtra("Header", cursor.getString(cursor.getColumnIndex("OpportunityName")));
startActivity(intent);
db.close();
}
public static void dataBnm(String dBNm) {
// Receive the database name from main class
DBName = dBNm;
openDataBaseAdapter.dbname(DBName);
}
}
Any assistance will be greatly appreciated.
Thanks
|
|
|
Last edited by louis84; November 9th, 2011 at 05:22 AM.
|
|