B
B
beregartur2017-10-23 21:15:40
Android
beregartur, 2017-10-23 21:15:40

Why is the android button handler not firing?

By clicking on the usual FloatingActionButton, I display a dialog box (without the code on which the application crashes - the modal window works).
Next, there should have been a button click processing (which is located on the modal window), but this is where the application crashes. Perhaps the handler needs to be moved to another location or specified explicitly using this? However, I don't know what exactly to do. Tell me please!

private int counter = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
                final Dialog dialog = new Dialog(MainActivity.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.dialog_layout);
                dialog.show();
                //инициализировали наш массив с элементами списка
                final ArrayList<View> allView = new ArrayList<View>();
                final ScrollView container = (ScrollView) findViewById(R.id.container);
                Button addButton = (Button) findViewById(R.id.button);
                addButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        counter++;
                        // береи данные из edit'a
                        EditText editText = (EditText) findViewById(R.id.editText);
                        float data = Float.parseFloat(editText.getText().toString());
                        //берем наш кастомный лейаут, находим все его элементы
                        final View view = getLayoutInflater().inflate(R.layout.item_layout, null);
                        ImageView deleteImage = (ImageView) view.findViewById(R.id.imageDellete);
                        TextView text = (TextView) view.findViewById(R.id.textView);
                        text.setText("Событие A" + counter +"=" + data);
                        //добавляем все что создаем в массив
                        allView.add(view);
                        //добавляем елементы в контейнер
                        container.addView(view);
                    }
                });
            }
        });
    }

59ee31b418dd7025338202.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-10-24
@red-barbarian

https://developer.android.com/guide/topics/ui/dial...
Well described about the dialogue. It also describes that you do not need to make dialogs, but use fragment dialog.
And what do you have in line 44? There is null. It's an error out of it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question