TableRow data updates with bright background

General Table of data (rows) update to keep up with some animation to the user's attention.
In Android, the color value of hex with 8 to 16, said two of them used to indicate the first two alpha channel, said after the six to rgb. In the process which, if within the specified time, the alpha channel from 0 adjusted to 0xff, on the realization of the highlight TableRow.

  • Here is the thread to achieve:
class ColorRefreshTask extends TimerTask {
                        final static int  DELAY_ONCE =200;
                        final static int TOTAL_RUNTIME = 3000;
                        final static int POWER_16_16 = 16 * 16* 16 * 16 * 16 * 16;
                        final static int INCREASE_ONCE =  0xff / (TOTAL_RUNTIME / DELAY_ONCE);
                        int color;
                        int id;
                        int startTime;
                        int alphaChannel;

                         * @param color (TableRow's current background color)
                         * @param id TableRow's id(user id)
                        public ColorRefreshTask(int color, int id) {
                                Log.d("color", "ready to set color!");
                                this.color = color;
                       = id;
                                this.startTime = 0;
                                this.alphaChannel = 0;

                        public void run(){

                                int colorComm = color -0xff000000;  //RGB color value;
                                int currColor = color;

                                if(startTime < TOTAL_RUNTIME) {
                                                startTime +=  DELAY_ONCE;
                                                alphaChannel +=  INCREASE_ONCE;
                                                currColor = POWER_16_16 *  alphaChannel  + colorComm;
                                                Log.d("color", Integer.toHexString(currColor));

                                else {


                        public void startTimer(){

                        private void sendMsg(int currColor){
                                Message message = messageHandler.obtainMessage();
                                message.what = MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND;
                                Bundle bundle = new Bundle();
                                bundle.putInt(MESSAGE_KEY_ID, id);
                                bundle.putInt(MESSAGE_KEY_COLOR, currColor);

                        public void stopTimer(){

  • Message processing part:

 private static final int MESSAGE_HANDLE_ID = 800;
          private static final int MESSAGE_HANDLE_ID_UPDATEROW_DATA = MESSAGE_HANDLE_ID + 1;
          private  Handler messageHandler = new Handler() {

                public void handleMessage(Message msg) {

                switch(msg.what) {
                        case  MESSAGE_HANDLE_ID_UPDATEROW_DATA:{
                                int id = msg.getData().getInt(MESSAGE_KEY_ID);
                                String fields[] = new String[5];
                                fields[0] = msg.getData().getString("fields1");
                                fields[1] = msg.getData().getString("fields2");
                                fields[2] = msg.getData().getString("fields3");
                                fields[3] = msg.getData().getString("fields4");
                                fields[4] = msg.getData().getString("fields5");
                                updateRowInTable(id, fields);

                        case  MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND:
                                int id = msg.getData().getInt(MESSAGE_KEY_ID);
                                int color = msg.getData().getInt(MESSAGE_KEY_COLOR);
                                TableRow tableRow= (TableRow)findViewById( id);
                                if(tableRow != null) {
                                        int count = tableRow.getChildCount();
                                        for(int index = 0; index < count; index++) {
                                                TextView child = (TextView)(tableRow.getChildAt(index));
                                                if(child != null) {




  • Data updates (other thread will call) part:

private final void updateRowInTable(int code,String[] otherFields) {
          TableRow tableRow= (TableRow)findViewById(code);
          if(tableRow == null)  {
                  Log.d("tablerow", "can't find row in the table!");
          int bgColorEnd = (otherFields[2].indexOf("-") >= 0)  ?  0xff2e8b57 : 0xffb22222;
      for(int index = 0; index < otherFields.length; index++) {
           int identity = code * 13  +(index+1);

          TextView textView=  (findViewById(identity)!= null)  ?  (TextView) findViewById(identity) :  new TextView(this);  

          if(otherFields[index].indexOf('-') >=0) {
          else if( index == 2) {
          else  {
          Log.d("tablerow", "updated  id:" + (code)  + ", value="  + otherFields[index] );
          if(findViewById(identity) == null){
                  Log.d("tablerow", "add new view!");
          else {
                  Log.d("tablerow", "upate view!");
      ColorRefreshTask refresh = new ColorRefreshTask(bgColorEnd,code);
      messageHandler.postDelayed(refresh, 50);  

分类:Mobile 时间:2010-06-04 人气:251
blog comments powered by Disqus


  • android - Set TextView part of the text and background color (highlight) 2010-11-20

    Set the background to highlight some text: public class HighLightActivity extends Activity { String strs=" My heart is so messed up, give me point blank ."; TextView textview; int start =3; int end = 5; /** Called when the activity is first crea

  • public void testStatementAddBatch () public void testConnCommit () 2011-09-01

    public void testStatementAddBatch() { Connection conn = null; Statement stmt = null; try { conn = getDBConnectionMsSqlBySuperAdmin(); stmt = conn.createStatement(); for(int i = 0; i < 100; i++) { String sql = " sql " + i; stmt.addBatch(sql);

  • Using javascript / css implementation GridView alternate row background color. Click the line color 2009-06-20

    Using javascript / css implementation GridView alternate row background color, click the line color Ask Bo a few days ago was found in someone clicks GridView question about the issue of line color, suddenly think of a long, long time ago, wrote an a

  • Using javascript / css to achieve GridView alternate row background color. Click the line color 2009-06-22

    Using javascript / css to achieve GridView alternate row background color, click the line color Asked a few days ago was found in Bo was asked click on the GridView row color problem, suddenly reminded of a long, long time ago, wrote an article in a

  • Set the background color of JTable row 2010-11-03

    (1) file used to implement the various features mentioned above. import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.util.Enumeration; import javax.swing.JTable; import javax.swing.RowSorter; impor

  • How to make Dialog background color transparent 2010-12-21

    Doing dialog dialog box, the default content, and border color inconsistencies. Individuals do not feel beautiful. To find a magical property to the same color. As follows: myDialog.setPlain (true); See API Description: /** * True to render the windo

  • Change ListView - item's background color 2010-06-24

    Forum today eoe.Android been raised Can then start to feel very simple to pull out a few things as related to the item on the background image then how to remove and refresh it? Therefore, the present depth should tell you how to do Existing ListView

  • Control the background color gradient 2010-09-23

    The example is mainly applied to the control without fillColors property and the need to customize the start position when the gradient. Gradient background color control class files package { import flash.display.*; import flash.geom.*; import flash

  • Control background color gradient 2010-09-23

    The main examples of properties for the controls and did not fillColors need to customize the gradient, when the starting position. Class file control background color gradient package { import flash.display.*; import flash.geom.*; import flash.utils

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.226 (s). 12 q(s)