How to update the textview of a fragment from the button's onclickListner of the same fragement.
@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);
}});
I am getting an compilation error when accessing the singleAlphabet TextView,how to acees the textview and please give me some ideas how to update the textview.
try to access the TextView like following code:
String tempAlphaString= single_Alphabet.getText().toString();
you can update TextView by
single_Alphabet.setText("your text");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.