Q:

Get ListView Item content when clicking it

I have a ListView that has items from the array i.e String[] statesList = {"Adult 1", "Adult 2","Adult 3","Child 1","Child 2","Child 1","Child 2","Child 2"};
Now I want to hide a TextView if the item is clicked apart from Adult. 
This is my function that I have written for populating the data in the listview 
protected void onCreate(Bundle savedInstanceState) {
    showPassengerListView();
}

    private void showPassengerListView() {

            String[]  passengerList ={"Adult 1", "Adult 2","Adult 3","Child 1","Child 2","Child 1","Child 2","Child 2"};
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android. R.layout.simple_list_item_1, android. R.id.text1, passengerList);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<? > parent, View view,
                        int position, long id) {
if((passengerList[position].contains("Child"))|| (passengerList[position].contains("Infant"))){
                    dateofBirth.setVisibility(View. VISIBLE);
                }else{
                    dateofBirth.setVisibility(View. GONE);
                }

                }
        });
          **passengerInformationPopup()**
    }

public void passengerInformationPopup() {
        final Dialog dialog= new Dialog(IweenBookingPage.this,R.style. Dialog_Fullscreen);
        dialog.setContentView(R.layout.passenger_details_dialog); 
        String[] tittlearray ={"Mr.","Mrs. ","Ms"};
        Spinner tittleSpinner = (Spinner) dialog.findViewById(R.id. Tittle);
         dateofBirth = (TextView)dialog.findViewById(R.id.dateofBirth);
        dateofBirth.setClickable(true);

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                android. R.layout.simple_spinner_item, tittlearray); 

        dataAdapter.setDropDownViewResource(android. R.layout.simple_spinner_item);
        tittleSpinner.setAdapter(dataAdapter);
        dialog.show();
    }

And i am getting the exception :
08-16 15:51:55.727: E/AndroidRuntime(15553): FATAL EXCEPTION: main
08-16 15:51:55.727: E/AndroidRuntime(15553): java.lang. NullPointerException
08-16 15:51:55.727: E/AndroidRuntime(15553):    at com.android.iweentravel. Book$5.onItemClick(Book.java:184)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.widget. AdapterView.performItemClick(AdapterView.java:298)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.widget. AbsListView.performItemClick(AbsListView.java:1114)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.widget. AbsListView$PerformClick.run(AbsListView.java:2937)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.widget. AbsListView$1.run(AbsListView.java:3695)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.os. Handler.handleCallback(Handler.java:615)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.os. Handler.dispatchMessage(Handler.java:92)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.os. Looper.loop(Looper.java:153)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at android.app. ActivityThread.main(ActivityThread.java:4987)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at java.lang.reflect. Method.invokeNative(Native Method)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at java.lang.reflect. Method.invoke(Method.java:511)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at com.android.internal.os. ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at com.android.internal.os. ZygoteInit.main(ZygoteInit.java:584)
08-16 15:51:55.727: E/AndroidRuntime(15553):    at dalvik.system. NativeStart.main(Native Method)

How to check which item has been clicked from the ListView?  On the basis of the item clicked I have to show/hide a TextView .  Main question is how to identify .  The items will be dynamic in the ListView .But have like Adult,Child ,Infant. 

A:

You can hide a TextView like that
TextView.setVisibility(View. GONE) 

or 
TextView.setVisibility(View. INVISIBLE) 

depending on what you want to do. 
A simple way of identifying an item inside your onItemClick() method would be:
listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<? > parent, View view, int position, long id) {
                 // for example like that
                 if(passengerlist[position].contains("Adult)") // do something

                 // or like that
                 TextView tv = (TextView) view.findViewById(R.id.text1);

                 if(tv.getText().toString().contains("Adult)") // do something
            }
        });

