0

テーブルを動的に作成したアクティビティがあります。テーブルは、SQLite データベースから取り込まれます。テーブル ヘッダーをクリックすると、それに応じてテーブルが並べ替えられます。

すべてが正常に機能しています。今、私の要件は、クリックされたときにテーブルヘッダーのテキストビューのテキストの色を変更することです。テキストの色は変更されていません。

これは、テーブルにデータを入力するメソッドです:

//Time ascending method
    public void populateTableTimeAscending()
    {
        getTimeNameTimeAsc();
        getStudentNameTimeAsc();
        follow_up_table.removeAllViews();
        //---------------Table Header-----------------------------------------------
        TableRow followup_tr_head = new TableRow(this);
        followup_tr_head.setId(10);
        followup_tr_head.setBackgroundResource(R.drawable.list_header);
        followup_tr_head.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));


        TextView time_name_title = new TextView(this);
        time_name_title.setId(20);
        time_name_title.setText("Time");
        time_name_title.setTextColor(Color.WHITE);
        time_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(time_name_title);// add the column to the table row here
        time_name_title.setTextSize(12);    

        TextView student_name_title = new TextView(this);
        student_name_title.setId(20);
        student_name_title.setText("Student Name");
        student_name_title.setTextColor(Color.WHITE);
        student_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(student_name_title);// add the column to the table row here
        student_name_title.setTextSize(12);    

        //----------------------On click time_name_title---------------------------------------

        time_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableTimeDescending();

            }
        });
        //----------------------On click time_name_title---------------------------------------

        //----------------------On click student_name_title---------------------------------------

        student_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableNameAscending();

            }
        });
        //----------------------On click student_name_title---------------------------------------


        follow_up_table.addView(followup_tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

        //--------------- Table Header-----------------------------------------------



        Iterator itr = time_name_list_time_asc.iterator();
        Iterator itr2 = student_name_list_time_asc.iterator();
        while(itr.hasNext())
        {
            while(itr2.hasNext())
            {

                //----------------table body------------------------------------------
                followup_tr_data = new TableRow(this);
                followup_tr_data.setId(10);
                followup_tr_data.setBackgroundResource(R.drawable.grey_list_bg);
                followup_tr_data.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));


                final TextView timeNameText = new TextView(this);
                timeNameText.setId(20);
                timeNameText.setText(Html.fromHtml(itr.next().toString()));
                timeNameText.setTextColor(Color.BLACK);
                timeNameText.setPadding(5,5,5,5);
                timeNameText.setTextSize(10);
                followup_tr_data.addView(timeNameText);// add the column to the table row here

                final TextView StudentNameText = new TextView(this);
                StudentNameText.setId(20);
                StudentNameText.setText(Html.fromHtml(itr2.next().toString()));
                StudentNameText.setTextColor(Color.BLACK);
                StudentNameText.setPadding(5,5,5,5);
                StudentNameText.setTextSize(10);
                followup_tr_data.addView(StudentNameText);// add the column to the table row here

                follow_up_table.addView(followup_tr_data, new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));

                //----------------table body------------------------------------------

            }

        }
    }  

time_name_title.setOnClickListener (new OnClickListener()内で、テキストの色を変更しようとしましたが、変更されませんでした。

----------------コード全体を編集----------------------------------- ---

public class TableActivity extends Activity {

    TableLayout follow_up_table;
    TableRow followup_tr_data;

    List<String> time_name_list_time_asc;
    List<String> student_name_list_time_asc;

    List<String> time_name_list_time_dsc;
    List<String> student_name_list_time_dsc;

    List<String> time_name_list_studname_asc;
    List<String> student_name_studname_asc;

    List<String> time_name_list_studname_dsc;
    List<String> student_name_list_studname_dsc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_table);

        follow_up_table=(TableLayout) findViewById(R.id.follow_up_table);



        //getTime();

        // database handler

        deleteRows(); 

        insertData("Morning", "2013-04-23 10:00:00", "Suresh Kumar");
        insertData("Morning", "2013-04-23 11:30:00", "Pravat Das");
        insertData("Evening", "2013-04-23 16:16:00", "Namita Roy");
        insertData("Evening", "2013-04-23 17:30:00", "Rakesh Mitra");
        insertData("After noon", "2013-04-23 14:27:00", "Anil Sarma");


        //       getTimeNameTimeAsc();
        //       getStudentNameTimeAsc();
        //       getTimeNameTimeDsc();
        //       getStudentNameTimeDsc();
        //       getTimeNameSyudentAsc();
        //       getStudentNameStudentAsc();
        //       getTimeNameStudentDsc();
        //       getStudentNameStudentDsc();



        populateTableTimeAscending();
    }

    //==================================================================================//  
    //=============Functions for Table View=====================================================//
    //==================================================================================//  

    //Time ascending method
    public void populateTableTimeAscending()
    {
        getTimeNameTimeAsc();
        getStudentNameTimeAsc();
        follow_up_table.removeAllViews();
        //---------------Table Header-----------------------------------------------
        TableRow followup_tr_head = new TableRow(this);
        followup_tr_head.setId(10);
        followup_tr_head.setBackgroundResource(R.drawable.list_header);
        followup_tr_head.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));


        final TextView time_name_title = new TextView(this);
        time_name_title.setId(20);
        time_name_title.setText("Time");
        time_name_title.setTextColor(Color.WHITE);
        time_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(time_name_title);// add the column to the table row here
        time_name_title.setTextSize(12);    

        TextView student_name_title = new TextView(this);
        student_name_title.setId(20);
        student_name_title.setText("Student Name");
        student_name_title.setTextColor(Color.WHITE);
        student_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(student_name_title);// add the column to the table row here
        student_name_title.setTextSize(12);    

        //----------------------On click time_name_title---------------------------------------

        time_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableTimeDescending();



            }
        });
        //----------------------On click time_name_title---------------------------------------

        //----------------------On click student_name_title---------------------------------------

        student_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableNameAscending();

            }
        });
        //----------------------On click student_name_title---------------------------------------


        follow_up_table.addView(followup_tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

        //--------------- Table Header-----------------------------------------------



        Iterator itr = time_name_list_time_asc.iterator();
        Iterator itr2 = student_name_list_time_asc.iterator();
        while(itr.hasNext())
        {
            while(itr2.hasNext())
            {

                //----------------table body------------------------------------------
                followup_tr_data = new TableRow(this);
                followup_tr_data.setId(10);
                followup_tr_data.setBackgroundResource(R.drawable.grey_list_bg);
                followup_tr_data.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));


                final TextView timeNameText = new TextView(this);
                timeNameText.setId(20);
                timeNameText.setText(Html.fromHtml(itr.next().toString()));
                timeNameText.setTextColor(Color.BLACK);
                timeNameText.setPadding(5,5,5,5);
                timeNameText.setTextSize(10);
                followup_tr_data.addView(timeNameText);// add the column to the table row here

                final TextView StudentNameText = new TextView(this);
                StudentNameText.setId(20);
                StudentNameText.setText(Html.fromHtml(itr2.next().toString()));
                StudentNameText.setTextColor(Color.BLACK);
                StudentNameText.setPadding(5,5,5,5);
                StudentNameText.setTextSize(10);
                followup_tr_data.addView(StudentNameText);// add the column to the table row here

                follow_up_table.addView(followup_tr_data, new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));

                //----------------table body------------------------------------------

            }

        }
    }




    //Time descending method
    public void populateTableTimeDescending()
    {
        getTimeNameTimeDsc();
        getStudentNameTimeDsc();
        follow_up_table.removeAllViews();

        //---------------Table Header-----------------------------------------------
        TableRow followup_tr_head = new TableRow(this);
        followup_tr_head.setId(10);
        followup_tr_head.setBackgroundResource(R.drawable.list_header);
        followup_tr_head.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));


        TextView time_name_title = new TextView(this);
        time_name_title.setId(20);
        time_name_title.setText("Time");
        time_name_title.setTextColor(Color.WHITE);
        time_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(time_name_title);// add the column to the table row here
        time_name_title.setTextSize(12);    

        TextView student_name_title = new TextView(this);
        student_name_title.setId(20);
        student_name_title.setText("Student Name");
        student_name_title.setTextColor(Color.WHITE);
        student_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(student_name_title);// add the column to the table row here
        student_name_title.setTextSize(12);    

        //----------------------On click setOnClickListener---------------------------------------

        time_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                populateTableTimeAscending();

            }
        });
        //----------------------On click setOnClickListener---------------------------------------

        //----------------------On click student_name_title---------------------------------------

                student_name_title.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        //makeAToast("Hello!");
                        populateTableNameAscending();

                    }
                });
                //----------------------On click student_name_title---------------------------------------


        follow_up_table.addView(followup_tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

        //--------------- Table Header-----------------------------------------------



        Iterator itr = time_name_list_time_dsc.iterator();
        Iterator itr2 = student_name_list_time_dsc.iterator();
        while(itr.hasNext())
        {
            while(itr2.hasNext())
            {

                //----------------table body------------------------------------------
                followup_tr_data = new TableRow(this);
                followup_tr_data.setId(10);
                followup_tr_data.setBackgroundResource(R.drawable.grey_list_bg);
                followup_tr_data.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));


                final TextView timeNameText = new TextView(this);
                timeNameText.setId(20);
                timeNameText.setText(Html.fromHtml(itr.next().toString()));
                timeNameText.setTextColor(Color.BLACK);
                timeNameText.setPadding(5,5,5,5);
                timeNameText.setTextSize(10);
                followup_tr_data.addView(timeNameText);// add the column to the table row here

                final TextView StudentNameText = new TextView(this);
                StudentNameText.setId(20);
                StudentNameText.setText(Html.fromHtml(itr2.next().toString()));
                StudentNameText.setTextColor(Color.BLACK);
                StudentNameText.setPadding(5,5,5,5);
                StudentNameText.setTextSize(10);
                followup_tr_data.addView(StudentNameText);// add the column to the table row here

                follow_up_table.addView(followup_tr_data, new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));

                //----------------table body------------------------------------------

            }

        }
    }


    //Name ascending method
    public void populateTableNameAscending()
    {
        getTimeNameSyudentAsc();
        getStudentNameStudentAsc();
        follow_up_table.removeAllViews();
        //---------------Table Header-----------------------------------------------
        TableRow followup_tr_head = new TableRow(this);
        followup_tr_head.setId(10);
        followup_tr_head.setBackgroundResource(R.drawable.list_header);
        followup_tr_head.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));


        TextView time_name_title = new TextView(this);
        time_name_title.setId(20);
        time_name_title.setText("Time");
        time_name_title.setTextColor(Color.WHITE);
        time_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(time_name_title);// add the column to the table row here
        time_name_title.setTextSize(12);    

        TextView student_name_title = new TextView(this);
        student_name_title.setId(20);
        student_name_title.setText("Student Name");
        student_name_title.setTextColor(Color.WHITE);
        student_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(student_name_title);// add the column to the table row here
        student_name_title.setTextSize(12);    

        //----------------------On click time_name_title---------------------------------------

        time_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableTimeDescending();

            }
        });
        //----------------------On click time_name_title---------------------------------------

        //----------------------On click student_name_title---------------------------------------

        student_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableNameDescending();

            }
        });
        //----------------------On click student_name_title---------------------------------------


        follow_up_table.addView(followup_tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

        //--------------- Table Header-----------------------------------------------



        Iterator itr = time_name_list_studname_asc.iterator();
        Iterator itr2 = student_name_studname_asc.iterator();
        while(itr.hasNext())
        {
            while(itr2.hasNext())
            {

                //----------------table body------------------------------------------
                followup_tr_data = new TableRow(this);
                followup_tr_data.setId(10);
                followup_tr_data.setBackgroundResource(R.drawable.grey_list_bg);
                followup_tr_data.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));


                final TextView timeNameText = new TextView(this);
                timeNameText.setId(20);
                timeNameText.setText(Html.fromHtml(itr.next().toString()));
                timeNameText.setTextColor(Color.BLACK);
                timeNameText.setPadding(5,5,5,5);
                timeNameText.setTextSize(10);
                followup_tr_data.addView(timeNameText);// add the column to the table row here

                final TextView StudentNameText = new TextView(this);
                StudentNameText.setId(20);
                StudentNameText.setText(Html.fromHtml(itr2.next().toString()));
                StudentNameText.setTextColor(Color.BLACK);
                StudentNameText.setPadding(5,5,5,5);
                StudentNameText.setTextSize(10);
                followup_tr_data.addView(StudentNameText);// add the column to the table row here

                follow_up_table.addView(followup_tr_data, new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));

                //----------------table body------------------------------------------

            }

        }
    }   



    //Name descending method
    public void populateTableNameDescending()
    {
        getTimeNameStudentDsc();
        getStudentNameStudentDsc();
        follow_up_table.removeAllViews();
        //---------------Table Header-----------------------------------------------
        TableRow followup_tr_head = new TableRow(this);
        followup_tr_head.setId(10);
        followup_tr_head.setBackgroundResource(R.drawable.list_header);
        followup_tr_head.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));


        TextView time_name_title = new TextView(this);
        time_name_title.setId(20);
        time_name_title.setText("Time");
        time_name_title.setTextColor(Color.WHITE);
        time_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(time_name_title);// add the column to the table row here
        time_name_title.setTextSize(12);    

        TextView student_name_title = new TextView(this);
        student_name_title.setId(20);
        student_name_title.setText("Student Name");
        student_name_title.setTextColor(Color.WHITE);
        student_name_title.setPadding(5,5,5,5);
        followup_tr_head.addView(student_name_title);// add the column to the table row here
        student_name_title.setTextSize(12);    

        //----------------------On click time_name_title---------------------------------------

        time_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableTimeDescending();

            }
        });
        //----------------------On click time_name_title---------------------------------------

        //----------------------On click student_name_title---------------------------------------

        student_name_title.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //makeAToast("Hello!");
                populateTableNameAscending();

            }
        });
        //----------------------On click student_name_title---------------------------------------


        follow_up_table.addView(followup_tr_head, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));

        //--------------- Table Header-----------------------------------------------



        Iterator itr = time_name_list_studname_dsc.iterator();
        Iterator itr2 = student_name_list_studname_dsc.iterator();
        while(itr.hasNext())
        {
            while(itr2.hasNext())
            {

                //----------------table body------------------------------------------
                followup_tr_data = new TableRow(this);
                followup_tr_data.setId(10);
                followup_tr_data.setBackgroundResource(R.drawable.grey_list_bg);
                followup_tr_data.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));


                final TextView timeNameText = new TextView(this);
                timeNameText.setId(20);
                timeNameText.setText(Html.fromHtml(itr.next().toString()));
                timeNameText.setTextColor(Color.BLACK);
                timeNameText.setPadding(5,5,5,5);
                timeNameText.setTextSize(10);
                followup_tr_data.addView(timeNameText);// add the column to the table row here

                final TextView StudentNameText = new TextView(this);
                StudentNameText.setId(20);
                StudentNameText.setText(Html.fromHtml(itr2.next().toString()));
                StudentNameText.setTextColor(Color.BLACK);
                StudentNameText.setPadding(5,5,5,5);
                StudentNameText.setTextSize(10);
                followup_tr_data.addView(StudentNameText);// add the column to the table row here

                follow_up_table.addView(followup_tr_data, new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));

                //----------------table body------------------------------------------

            }

        }
    }   




    //==================================================================================//  
    //=============Functions for Table View=====================================================//
    //==================================================================================//      




    //==================================================================================//  
    //=============Functions for DB=====================================================//
    //==================================================================================//  
    //=================Time name ascending=================================
    public void getTimeNameTimeAsc()
    {

        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        time_name_list_time_asc = db.getTimeNameTimeAsc();
        Iterator itr = time_name_list_time_asc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }

    }

    public void getStudentNameTimeAsc()
    {
        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        student_name_list_time_asc = db.getStudentNameTimeAsc();
        Iterator itr = student_name_list_time_asc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }
    }

    //=================Time name ascending=================================



    //=================Time name descending=================================
    public void getTimeNameTimeDsc()
    {

        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        time_name_list_time_dsc = db.getTimeNameTimeDsc();
        Iterator itr = time_name_list_time_dsc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }

    }

    public void getStudentNameTimeDsc()
    {
        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        student_name_list_time_dsc = db.getStudentNameTimeDsc();
        Iterator itr = student_name_list_time_dsc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }
    }

    //=================Time name descending=================================


    //=================Student name ascending=================================
    public void getTimeNameSyudentAsc()
    {

        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        time_name_list_studname_asc = db.getTimeNameSyudentAsc();
        Iterator itr = time_name_list_studname_asc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }

    }

    public void getStudentNameStudentAsc()
    {
        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        student_name_studname_asc = db.getStudentNameStudentAsc();
        Iterator itr = student_name_studname_asc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }
    }

    //=================Student name ascending=================================



    //=================Student name descending=================================
    public void getTimeNameStudentDsc()
    {

        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        time_name_list_studname_dsc = db.getTimeNameStudentDsc();
        Iterator itr = time_name_list_studname_dsc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }

    }

    public void getStudentNameStudentDsc()
    {
        DatabaseHandler db = new DatabaseHandler(getApplicationContext());

        student_name_list_studname_dsc = db.getStudentNameStudentDsc();
        Iterator itr = student_name_list_studname_dsc.iterator();
        while(itr.hasNext())
        {
            System.out.println(itr.next());
        }
    }

    //=================Student name descending=================================



    //method to insert data into local database
    public void insertData(String timeName, String time, String studentName)
    {
        DatabaseHandler db = new DatabaseHandler(TableActivity.this);
        ContentValues values = new ContentValues();
        //db.createDataBase();
        values.put("timeName",timeName);
        values.put("time",time);
        values.put("studentName",studentName);

        db.insertValues(timeName, time, studentName);
        db.close();

    }

    //method to delete all rows
    public void deleteRows()
    {
        DatabaseHandler db = new DatabaseHandler(getApplicationContext());
        db.deleteAllData();
        db.close();
    }
    //==================================================================================//  
    //=============Functions for DB=====================================================//
    //==================================================================================//  

    //method to show toast message
    public void makeAToast(String str) {
        //yet to implement
        Toast toast = Toast.makeText(this,str, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}
4

6 に答える 6

3

これを使用することもできます:

textview.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    textview.setTextColor(Color.BLUE);
                    break;
                case MotionEvent.ACTION_UP:
                    textview.setTextColor(Color.BLACk);
                    break;
                }
                return false;
            }
        });
于 2013-04-25T09:34:24.720 に答える
1

適切な TextView でテキストの色を変更しようとしていることを確認し、populateTableTimeDescending(); の後に setTextColor を呼び出してみてください。

于 2013-04-25T06:45:21.667 に答える
0

ここでは、4 桁の後に、16 進数のカラー コードを使用して好きな色を設定できます。

time_name_title.setTextColor(0xffffffff);
于 2013-04-25T11:48:06.127 に答える
0
 final TextView tv = new TextView(this);
    tv.setText("Sample TextView");

    rl = (RelativeLayout) findViewById(R.id.rl);
    rl.addView(tv);
    tv.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            populateTableTimeDescending();//since you are setting the color of the TextView back to same(white) again in this method, set the color of the textView after calling the method. 
            tv.setTextColor(Color.parseColor("#FF0000")); //**edited**
        }
    });
于 2013-04-25T06:48:39.757 に答える