Диалог во фрагменте: - PullRequest
       31

Диалог во фрагменте:

0 голосов
/ 28 февраля 2019

я пытаюсь добавить диалог в мой фрагмент.У меня есть MainActivity (меню Drawer), которое содержит мои фрагменты.В одном фрагменте я хочу показать диалог, но всегда получаю нулевую ссылку на объект, когда пытаюсь изменить вещи в представлении / или пытаюсь реализовать прослушиватель действий.

public class Fragment_Statistik extends Fragment implements View.OnClickListener {

TextView currentBerrys,currentFish,currentTrees,currentLumber,currentStones,currentStonebricks;
ProgressBar progressBarBerrys, progressBarFish, progressBarTrees,progressBarLumber,progressBarStones,progressBarStonebricks;
FloatingActionButton fab;
Button upgrade;
boolean running = true;
Dialog popupUpgradeWarehouse;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_statistik, container, false);

}

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    fab = getView().findViewById(R.id.floatingActionButton);
    currentBerrys = getView().findViewById(R.id.textView_current_berrys);
    currentFish = getView().findViewById(R.id.textView_current_fish);
    currentTrees = getView().findViewById(R.id.textView_current_trees);
    currentLumber = getView().findViewById(R.id.textView_current_lumber);
    currentStones = getView().findViewById(R.id.textView_current_stone);
    currentStonebricks = getView().findViewById(R.id.textView_current_stonebricks);
    progressBarBerrys = getView().findViewById(R.id.progressBarBerrys);
    progressBarFish = getView().findViewById(R.id.progressBarFish);
    progressBarTrees = getView().findViewById(R.id.progressBarTree);
    progressBarLumber = getView().findViewById(R.id.progressBarLumber);
    progressBarStones = getView().findViewById(R.id.progressBarStone);
    progressBarStonebricks = getView().findViewById(R.id.progressBarStonebrick);
    fab.setOnClickListener(this);
    popupUpgradeWarehouse = new Dialog(getContext());}

showPopupupgradeWarehouse работает.Когда я удаляю весь другой код, я получаю диалоговое окно.

    public void showPopupUpgradeWarehouse() {
    popupUpgradeWarehouse.setContentView(R.layout.popup_upgrade_warehouse);
    upgrade = getView().findViewById(R.id.popupButtonUpgrade);
    ImageView popupImageViewClose;
    popupImageViewClose = getView().findViewById(R.id.popupImageViewClose);

    upgrade.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    popupUpgradeWarehouse.show();
}
...