Home > Mobile >  Small white ask a question, fragments of button click event can't response
Small white ask a question, fragments of button click event can't response

Time:12-25

HomeFragment. Java code as shown below:
Package com. Example. Test1;

The import android. OS. Bundle;
The import android. Support. The annotation. NonNull;
The import android. Support. The annotation. Nullable;
The import android. Support. The v4. App. Fragments;
The import android. Util. Log;
The import android. View. LayoutInflater;
The import android. View. The view;
The import android. View. ViewGroup;
The import android. Widget. The Button;
The import android. Widget. TextView;
The import android. Widget. Toast;

Public class HomeFragment extends fragments {

Private Button Button;
Private TextView TextView;
Private View View;
@ Nullable
@ Override
Public View onCreateView (@ NonNull LayoutInflater inflater, @ Nullable ViewGroup container, @ Nullable Bundle savedInstanceState) {
View=inflater. Inflate (R.l ayout. Home, container, false);
Return the view;
}

@ Override
Public void onActivityCreated (@ Nullable Bundle savedInstanceState) {
Super. OnActivityCreated (savedInstanceState);
The button=(button) view. The findViewById (R.i d.z y);
TextView=(textView) view. The findViewById (R.i which est);
Button. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View View) {
TextView. SetText (" response to the click event success ");
}
});
}
}
Unable to update the textview, ask everybody to help, I am also just started to learn

CodePudding user response:

Stick the XML file

CodePudding user response:

First determine the click event success

CodePudding user response:

See you again
In onCreateView instance control, in the onActivityCreated add listeners

CodePudding user response:

In onCreateView instance control

 
Public View onCreateView (@ NonNull LayoutInflater inflater, @ Nullable ViewGroup container, @ Nullable Bundle savedInstanceState) {
View=inflater. Inflate (R.l ayout. Home, container, false);
The button=(button) view. The findViewById (R.i d.z y);
TextView=(textView) view. The findViewById (R.i which est);
Return the view;
}



  • Related