偶尔在LG G2上使用空白TextView(Android 4.4.2)

时间:2014-07-10 02:50:59

标签: android textview

我正在编写一个简单的应用程序,其中日语字符在屏幕中间显示为TextView,底部有4个按钮(home,shuffle,sound和next)。按下下一个按钮时,下一个字符将显示在TextView中。

该应用程序在日食模拟器和我的三星Galaxy S2(Android 4.0.4)上完美运行。但是,在我的LG G2(Android 4.4.2)上,偶尔(可能每30个字符一次),当我点击下一个按钮时,我得到一个空白的TextView。

我做了以下实验:

1)我添加了一些调试代码,用于在调用setText()之前和之后转储Toast上的字符值,并在Toast上显示正确的值。

2)我按下了声音'当TextView为空白并确认声音按钮与正确的字符相关联时按钮。

3)我在调用setText()之后立即添加了一秒延迟,看看在设置正确的字符后我是否覆盖了TextView。在这种情况下,我希望首先在TextView中设置正确的字符,然后在一秒延迟后变为空白。但是,当我点击下一个按钮时,我看到空白的TextView。

所以,我想,也许过早,setText()以某种方式清除TextView。

有人知道问题可能是什么吗?

我的部分代码如下所示:

public class KatakanaFragment extends Fragment {
    private ImageButton    mNextButton;
    private TextView        mCharTextView;

    private void updateChar() {
        int            strId;
        Katakana[]    activeKatakana;

        activeKatakana = KatakanaTable.getActiveChars();
        if ((activeKatakana == null) || (activeKatakana.length == 0)) {
            Toast.makeText(getActivity(), "No Char Selected", Toast.LENGTH_SHORT).show();
            return;
        }

        if (activeKatakana.length <= KatakanaTable.sCurrentIndex) {
            Toast.makeText(getActivity(), "Current Index Too Big", Toast.LENGTH_SHORT).show();
            return;
        }

        strId = activeKatakana[KatakanaTable.sCurrentIndex].getCharId();
        mCharTextView.setTextSize(getResources().getDimension(R.dimen.textsize));
        mCharTextView.setText(strId);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent,
        Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.activity_katakana, parent, false);

        mCharTextView = (TextView)v.findViewById(R.id.char_text_view);

        mNextButton = (ImageButton)v.findViewById(R.id.next_button);
        mNextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (KatakanaTable.getActiveChars().length == 0) {
                    Intent i = new Intent(getActivity(), MainActivity.class);
                    startActivity(i);
                    return;
                }
                KatakanaTable.sCurrentIndex = (KatakanaTable.sCurrentIndex + 1) % KatakanaTable.getActiveChars().length;
                updateChar();
            }
        });

        updateChar();
        return v;
    }
}

0 个答案:

没有答案
相关问题