Set text to textview in poor handler performance

Since Android does not support showing the day for a date, I added a TextView to my layout.

In DatePicker, I put onDateChangedListener. When the date changes, I determine the day of the week and then set it through a handler to make sure that this is done in the user interface thread:

// this is being called when the date changes on the DatePicker
public void onDateChanged(DatePicker view, final int year,
                final int monthOfYear, final int dayOfMonth) {
    String dayOfTheWeek = null;

    // some code here to set the 'dayOfTheWeek' string

    h.sendMessage(h.obtainMessage(0, dayOfTheWeek));
}

final Handler h = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        dayOfWeekTextView.setText((String)msg.obj);
    }
};

My problem: when I look at the days in widgets ( Android 4.0 U , I'm not sure! I check what the problem is and not how I determine what String is, it really is setText()in the handler. Commenting out that the part and everything is fine Also, setting hard-coded text there ( dayOfWeekTextView.setText("SOMETHING');) gives the same problem. This causes fluctuations DatePicker.

setText() ? Wunderlist , , , .

HTC One X. ?

Edit:

, Wunderlist! , , DialogFragment. , Wunderlist TextView. ( ;))

, 'getDialog(). setTitle (dayOfWeek)', . : setText ...?

+5
4

7 TextView . , 8 , .


. , , , , setText. , .

+3

. wrap-content, , , . .

+3

:

t1.setText(""+string_name);

TextView EditText

0

I tried to implement the same thing using the same "handler" approach that you stated, and it works fine with n.

Try this code:

final DatePicker dp = (DatePicker)findViewById(R.id.datePicker1);

        dp.init(2012, 6, 17, new OnDateChangedListener() {

            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear,
                    final int dayOfMonth) {

                handler.post(new Runnable() {

                    @Override
                    public void run() {

                        TextView tv = (TextView) findViewById(R.id.textView1);

                        // some code here to set the 'dayOfTheWeek' string


                        tv.setText(Integer.toString(dayOfTheWeek));   // (if you want to set a number of day instead of its name)

                                           //  OR

                        tv.setText(dayOfTheWeek);   

                    }
                });

            }
        });

The catch here is to use the Wrapper Integer class to convert an int value to a string. If you pass the " int plane ", it will throw an Not Found exception .

0
source

All Articles