Source:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MyApplication application = (MyApplication) this.getActivity().getApplicationContext(); this.busManager = application.getBusManager(); this.busManager.addObserver(this); this.wifiBroadcastReceiver = application.getWifiBroadcastReceiver(); this.wifiBroadcastReceiver.addObserver(this); final View rootView = inflater.inflate(R.layout.fragment_flag_vehicle, container, false); flagAdapter = new FlagViewAdapter(getActivity(), flagButtons); final TextView textView = (TextView) rootView.findViewById(R.id.textViewBusInformation); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { WifiHelper wifiHelper = new WifiHelper(getActivity()); boolean wifiIsEnabled = wifiHelper.isWifiEnabled(); if (wifiIsEnabled) { textView.setText(R.string.loading_looking_for_vehicle); wifiHelper.initiateWifiScan(); } else { textView.setText(R.string.activating_wifi); wifiHelper.enableWifi(); } } }); this.updateBusText(rootView); GridView flagGrid = (GridView) rootView.findViewById(R.id.flagGridView); flagGrid.setAdapter(flagAdapter); flagGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { FlagButton button = flagAdapter.getItem(i); FlagVehicleDetailFragment detailFragment = new FlagVehicleDetailFragment(); Bundle args = new Bundle(); args.putInt(FlagVehicleDetailFragment.ARG_POSITION, mCurrentPosition); args.putInt("flag_image_ID", button.getImageID()); args.putString("flag_description", button.getDescription()); args.putInt("flag_type_ID", button.getType().getID()); detailFragment.setArguments(args); FragmentTransaction transaction = getActivity().getSupportFragmentManager(). beginTransaction(); transaction.replace(R.id.content_frame, detailFragment); transaction.addToBackStack(null); transaction.commit(); } }); return rootView; }

Target:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MyApplication application = (MyApplication) this.getActivity().getApplicationContext(); this.busManager = application.getBusManager(); this.busManager.addObserver(this); this.wifiBroadcastReceiver = application.getWifiBroadcastReceiver(); this.wifiBroadcastReceiver.addObserver(this); final View rootView = inflater.inflate(R.layout.fragment_flag_vehicle, container, false); flagAdapter = new FlagViewAdapter(getActivity(), flagButtons); final TextView textView = (TextView) rootView.findViewById(R.id.textViewBusInformation); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { WifiHelper wifiHelper = new WifiHelper(getActivity()); boolean wifiIsEnabled = wifiHelper.isWifiEnabled(); if (wifiIsEnabled) { textView.setText(R.string.loading_looking_for_vehicle); wifiHelper.initiateWifiScan(); } else { textView.setText(R.string.activating_wifi); wifiHelper.enableWifi(); } } }); this.updateBusText(rootView); GridView flagGrid = (GridView) rootView.findViewById(R.id.flagGridView); flagGrid.setAdapter(flagAdapter); flagGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { FlagButton button = flagAdapter.getItem(i); FlagVehicleDetailFragment detailFragment = new FlagVehicleDetailFragment(); Bundle args = new Bundle(); args.putInt(FlagVehicleDetailFragment.ARG_POSITION, mCurrentPosition); args.putInt("flag_image_ID", button.getImageID()); args.putString("flag_description", button.getDescription()); args.putInt("flag_type_ID", button.getType().getId()); detailFragment.setArguments(args); FragmentTransaction transaction = getActivity().getSupportFragmentManager(). beginTransaction(); transaction.replace(R.id.content_frame, detailFragment); transaction.addToBackStack(null); transaction.commit(); } }); return rootView; }