【问题标题】:Getting the value of TextView , update in the fragment when a button is clicked and called onClickListener获取 TextView 的值,在单击按钮并调用 onClickListener 时在片段中更新
【发布时间】:2014-09-22 12:59:35
【问题描述】:

如何从同一个片段的按钮的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 的想法。

【问题讨论】:

    标签: android android-fragments button textview onclicklistener


    【解决方案1】:

    尝试访问 TextView,如下代码:

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

    你可以通过

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      • 2012-08-29
      相关资源
      最近更新 更多