android - I can't change the textview text by pressing a button -
Hello all I get I 0 errors to change the dynamic TextView text in Android Studio but I am struggling when I program runs 'm testing but at that time I button crash program
CODE:
spreads public square MyFragment piece (Tekstwu TV button [] Bitian = new Button [30]; TextView TV; @Override Watch public onCreateView (LayoutInflater inflater, ViewGroup Tenor, bundled savedInstanceState) {// TODO Auto refer method stub myFragmentView = inflater.inflate (R.layout.fragmentlayout, container, false); Tv = (TextView) findViewById (R.id.textView1); (Int i = 0; i & lt; 30; i ++) {Bitian [i] = new button (getActivity ()); btn [i] .setText ( "1"); btn [i] .setLayoutParams (new LayoutParams ( Layoutpramskwrap_kantent, `Layoutpramskwrap_kantent)); 'button [e] Ksetvisibiliti (Wukvizibl) button [e] Ksetid (e); Linarlyutkadviav (button [e]) button [2] Ksetonkliklistener (BtnOnClickListener); Button.OnClickListener btnOnClickListener = new Button.OnClickListener () {@Override public void onClick (View v) {// TODO Auto-generated method stub if (v == btn [2]) {tv.setText (btn [2]. Gettext ()); }}}; It does not have all the parts of the code (it has 2 pieces which is one of them) but I can not share all the programs, but these are all about the parts. My problem. If you have something to say then please ask it. "Text" itemprop = "text"> Advance
If textView1 is in your main activity again in your piece and not (thanks to TextView) FindViewById (R.id.textView1); will return to zero. If you want to set the text view to pieces in your main activity, then call it on a main activity by calling a public method.
Add a method like this to your main activity:
Public Zero Settypetext (String Text) {TextView TextView = (TextView) SearchVBIID (RIDTexView1 ); If (textview! = Null) textview.setText (text); }
Then call the method to change your piece:
button. Public Zero onClick (see v) {if (v == btn [2]) ((MainActivity) getActivity ()) setTextViewText (btn [2] .getText ()). }};
Change main activity on the name of your main activity class.
Comments
Post a Comment