これは、私がビューを作成しているときのビットです。
public static int a=0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
a++;
View view = inflater.inflate(R.layout.fragment_layout, container, false);
editText = (EditText) view.findViewById(R.id.amount);
TextView tv = (TextView) view.findViewById(R.id.textView1);
Button button = (Button) view.findViewById(R.id.addTransaction);
button.setOnClickListener(this); ///fragments implements OnClickListener
editText.setText(""+a);
tv.setText(""+a);
return view;
}
このフラグメントを初めてロードすると、editText は空ですが、フラグメントを再度ロードすると、editText の値は前の実行と同じになります。
誰かが私が間違っていることを知っていますか? どうすれば修正できますか?
** 編集
コードを少し変更しました。今では、フラグメントをロードするたびにインクリメントされます。そして、奇妙な行動に気づきました。tv には a の実際の値がありますが、editText にはまだ古い値があります