Home > Mobile >  Why fragments of the button is invalid in the onActivityCreated?
Why fragments of the button is invalid in the onActivityCreated?

Time:10-29

In order to facilitate inspection BT_in button I set became serText but still is invalid, each button is useless, I write the code according to the book and Internet I feel no difference but is not achieve them, other don't need to look, I just want to know why BT_in button is invalid?

 
Public class Fragment3 extends fragments {

Private final String TABLENAME="Money_TB";
Private EditText ET_in ET_out;
Private Button BT_in, BT_out BT_re;
Private SQLiteDatabase db.
Private TextView Money;
DBOpenHelper helper;

Public Fragment3 () {

}

@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//TODO Auto - generated method stub
Return inflater. Inflate (R.l ayout tab03, container, false);
}

@ Override
Public void onActivityCreated (Bundle savedInstanceState) {
//TODO Auto - generated method stub
Super. OnActivityCreated (savedInstanceState);

Money=(TextView) getActivity (). The findViewById (R.i d.m oney2);
Int num=Integer. ParseInt (Money. The getText (), toString ());

ET_in=(EditText) getActivity (). The findViewById (R.i d.m oneyin);
ET_out=(EditText) getActivity (). The findViewById (R.i d.m oneyout);

Helper=new DBOpenHelper (getActivity ());

BT_in=(Button) getActivity (). The findViewById (R.i d.m oneyinb);
BT_out=(Button) getActivity (). The findViewById (R.i d.m oneyoutb);
BT_re=(Button) getActivity (). The findViewById (R.i d.r eferesh);

BT_re. SetOnClickListener (new View. An OnClickListener () {

@ Override
Public void onClick (View v) {
//TODO Auto - generated method stub
The db=helper. GetWritableDatabase ();
The Refresh ();
}

Private void Refresh () {
//TODO Auto - generated method stub
ContentValues values=new ContentValues ();
Int money1=10000;
Values. The put (" money ", money1);
The update (TABLENAME values, null, null);
}
});

BT_in. SetOnClickListener (new View. An OnClickListener () {

@ Override
Public void onClick (View v) {
//TODO Auto - generated method stub
ET_in. SetText (" 123 ");
}

Private void In () {
//TODO Auto - generated method stub

ContentValues values=new ContentValues ();
String ETIN=ET_in. GetText (). The toString ();
Int num=Integer. ParseInt (ETIN);
Values. The put (" money ", num);
The insert (TABLENAME, null values);

Cursor Cursor=db. Query (" diary ", null, null, null, null, null, null);
Money. The setText (num);
ET_in. SetText (" ");
}
});
BT_out. SetOnClickListener (new View. An OnClickListener () {

@ Override
Public void onClick (View arg0) {
//TODO Auto - generated method stub
The db=helper. GetWritableDatabase ();
Out ();
}

Private void Out () {
//TODO Auto - generated method stub

}
});
}
}

CodePudding user response:

Run time error, not an error, this button is not empty, should be no problem, the problem should be out in your onclick implementation

CodePudding user response:

In that line, debug directly to the setText call didn't see

CodePudding user response:

Write the code in the onViewCreated try

CodePudding user response:

(TextView) getActivity (). The findViewById (R.i d.m oney2); You this is to find the layout of the activity file View, is not a fragment, so all the events are not response,
  • Related