How to resolve findViewById inside fragments

Hello Everyone Below is code from Fragment 1.

public class notices extends Fragment implements View.OnClickListener {

private Button fragment_btn_1;

private Button fragment_btn_2;

//the URL having the json data

private static final String JSON_URL = "https://simplifiedcoding.net/demos/view-flipper/heroes.php";

//listview object

ListView listView;

//the hero list where we will store all the hero objects after parsing json

List heroList;

public static notices newInstance() {

notices fragment = new notices();

return fragment;

}

@Nullable

@Override

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_notices, container, false);

fragment_btn_1.setOnClickListener(this);

fragment_btn_2.setOnClickListener(this);

listView = (ListView) view.findViewById(R.id.listView);

heroList = new ArrayList<>();

//this method will fetch and parse the data

loadHeroList();

return view;

}

private void loadHeroList() {

final ProgressBar progressBar...

Read More »

By: StackOverFlow - Tuesday, 13 March

Related Posts