Categories
Mastering Development

Can anyone please explain why my app is not launching

I tried to make my app inflating with 2 EditTexts and Spinner when button is pressed, but it is not launching.

I’m new to programming, so there can be some simple mistakes. I found out:

  1. Without spinner app works.
  1. Logcat shows no errors.

Please help me. Thank you in advance.

My java code:

package com.example.test2;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Spinner spinner=findViewById(R.id.spinner1);
    ArrayAdapter<CharSequence> adapter= ArrayAdapter.createFromResource(this, R.array.categories, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

int i=1;
int numberOfButtons = 2;
public void buttonCreate (View view){
    for(i=1;i<numberOfButtons;i++){
        ViewGroup parentLayout = (LinearLayout)findViewById(R.id.parentLayout);
        LayoutInflater layoutInflater = getLayoutInflater();
        view = layoutInflater.inflate(R.layout.button_layout, parentLayout, false);
        LinearLayout buttonLayout = (LinearLayout) view.findViewById(R.id.createdLayout);
        parentLayout.addView(buttonLayout);
    }
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *