Hello all I am struggling to change the textview text dynamically in android studio i get 0 errors but when i am testing the program runs but at the time i press the button program crashes /////////
public class MyFragment extends Fragment { TextView tv;
Button[] btn = new Button[30];
Button[] btn1 = new Button[30];
Button[] btn2 = new Button[30];@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View myFragmentView = inflater.inflate(R.layout.fragmentlayout, container, false);
for (int i = 0; i < 30; i++) { btn[i] = new Button(getActivity()); btn[i].setText("1"); btn[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); btn[i].setVisibility(View.VISIBLE); btn[i].setId(i); linearLayout.addView(btn[i]);
btn[2].setOnClickListener(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());
}
}
};
/////////////
This is not the all parts of the code but i can't share all of the program itself, but these are all the parts about my problem. If you have anything to say please say it. Thanks in advance
Aucun commentaire:
Enregistrer un commentaire