Answer the question
In order to leave comments, you need to log in
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);
}
});
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question