获取TextView的值,在单击按钮并调用onClickListener时更新片段

时间:2014-09-22 12:59:35

标签: button textview fragment onclicklistener

如何从同一片段的按钮onclickListner更新片段的textview。

@Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(
                    R.layout.fragment_practicing_alphabet, container, false);
             TextView singleAlphabet=(TextView) rootView.findViewById(R.id.single_alphabet);
            ImageButton previousImage=(ImageButton) rootView.findViewById(R.id.btn_backward_arrow);

previousImage.setOnClickListener(new OnClickListener(){
                public void onClick(View v)
                {
                    String tempAlphaString=(String) singleAlphabet.getText();
                    char tempAlphaChar=(char) (tempAlphaString.charAt(0)+1);
                    singleAlphabet.setText(tempAlphaChar);

                }});

访问singleAlphabet TextView时出现编译错误,如何查看textview,请给我一些如何更新textview的建议。

1 个答案:

答案 0 :(得分:0)

尝试访问TextView,如下面的代码:

String tempAlphaString= single_Alphabet.getText().toString(); 

您可以通过

更新TextView
 single_Alphabet.setText("your text");