Непоследовательное поведение Expandable ListView - PullRequest
0 голосов
/ 24 октября 2018

Я создаю приложение с расширяемым ListView.Я могу добавить групповые заголовки (тренировки) и дочерние (упражнения).

Я решил добавить фиктивного ребенка в каждую тренировку с пользовательским макетом (который содержит только кнопку).Идея кнопок в том, чтобы показать диалоговое окно, которое получает информацию от пользователя.

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

enter image description here

Когда я добавляю еще что-то, все идет не так.

Нет кнопки для первой тренировки.

enter image description here.

Первое упражнение изпервая тренировка стала первым упражнением второй тренировки.

enter image description here

Ошибка, полученная от отладчика:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.ofek.prolog, PID: 11532
    java.lang.NullPointerException
        at com.example.ofek.prolog.MyListAdapter.getChildView(MyListAdapter.java:112)

строка 112 - это TextView, который я настраиваю, но он не работает.порядок детей был неправильным, поэтому был задан другой макет.

и это мой список адаптеров getChildView:

@Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                             View view, ViewGroup parent) {

        ExerciseItem exerciseItem = (ExerciseItem) getChild(groupPosition, childPosition);
        //Set Bundle and pass the group position
        final Bundle bundle = new Bundle();
        bundle.putInt("groupPosition", groupPosition);

        if (view == null) {
            LayoutInflater infalInflater = (LayoutInflater)
                    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            if (exerciseItem.isFirstChild()) {
                view = infalInflater.inflate(R.layout.button_exercise_row, null);
                Button newExercise = view.findViewById(R.id.add_exercise);
                newExercise.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //Set FragmentManager
                        FragmentManager fragmentManager = ((AppCompatActivity) context).getFragmentManager();
                        //create a dialog that ask the details of the exercise
                        NewExerciseChildFragment newExerciseDialog = new NewExerciseChildFragment();
                        newExerciseDialog.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomNewDialogFragment);
                        newExerciseDialog.setArguments(bundle);
                        newExerciseDialog.show(fragmentManager, "showExerciseDialog");
                    }
                });
            }else{
                view = infalInflater.inflate(R.layout.exercise_row, null);
            }
        }
        if (!exerciseItem.isFirstChild()){
            //Some visual code
        }

        return view;
    }

Спасибо

...