how to put if statement inside a button's onclicklistener in android : I am working on my major project and I want my button to open different intents based on the string array value obtained. I used if and else if statements inside the onclicklistener of the button but it won't click anymore. Please help me.


This is my XML file:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

    <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    app:cardCornerRadius="3dp"
                    app:cardElevation="2dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:padding="@dimen/spacing_large">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:paddingBottom="@dimen/spacing_middle"
                            android:text="Syllabus"
                            android:textAppearance="@style/TextAppearance.AppCompat.Title" />

                        <Button
                            android:id="@+id/buttonpdf"
                            style="@style/Widget.AppCompat.Button"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@color/colorPrimary"
                            android:text="Open Book" />


                    </LinearLayout> 

<!-- end snippet -->

And this is the java file for the same activity:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

    public class ActivityBookDetails extends AppCompatActivity {

        public static final String EXTRA_OBJCT = "com.app.sample.recipe.OBJ";

        private Book book;
        private FloatingActionButton fab;
        private View parent_view;
        
        Button button;
        String[] obj;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(activity_book_details);
            parent_view = findViewById(android.R.id.content);
            button = (Button)findViewById(R.id.buttonpdf);
            

            book = (Book) getIntent().getSerializableExtra(EXTRA_OBJCT);
            fab = (FloatingActionButton) findViewById(R.id.fab);
            fabToggle();
            setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle(book.getName());

            ((ImageView) findViewById(R.id.image)).setImageResource(book.getPhoto());

            LinearLayout subjects = (LinearLayout) findViewById(R.id.subjects);


            final String[] title_subjects = getResources().getStringArray(R.array.Subjects);
            addIngredientsList(subjects, title_subjects);
            obj = title_subjects;

            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if ("Soft Computing".equals(obj)) {
                        Intent intent = new Intent(ActivityBookDetails.this, pdfviewactivity.class);

                        startActivity(intent);
                    }
                    else if ("Web Engineering".equals(obj)) {
                        Intent intent = new Intent(ActivityBookDetails.this, pdfweben.class);

                        startActivity(intent);
                    }
                    else if ("Network Management".equals(obj)) {
                        Intent intent = new Intent(ActivityBookDetails.this, pdfnetwork.class);

                        startActivity(intent);
                    }
                    else if ("Wireless Network".equals(obj)) {
                        Intent intent = new Intent(ActivityBookDetails.this, pdfwireless.class);

                        startActivity(intent);
                    }
                }
            });

<!-- end snippet -->

I want my if else condition to work on the basis of the value of string array.

This is a sample java file of one of the given intents:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

    public class pdfwireless extends AppCompatActivity {
        PDFView pdfView;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_pdfwireless);
            pdfView = (PDFView)findViewById(R.id.pdfView);
            pdfView.fromAsset("wirelessnetwork.pdf").load();
        }
    }

<!-- end snippet -->

