The findViewById (int) method is undefined for the ListViewFragment type


I am getting the following error:

The method findViewById(int) is undefined for the type ListViewFragment

And the ListViewFragment is

package com.yogeshojha.nagariksahayata;

import java.util.ArrayList;
import java.util.List;

import com.yogeshojha.nagariksahayata.R;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class ListViewFragment extends Fragment implements OnItemSelectedListener{
public ListViewFragment(){}
Spinner mspinner;
TextView viewvdc;//declare spinner globally
ArrayAdapter<String> adapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    String [] name = {"नेपाली नागरिकता","नेपाली नागरिकता","नेपाली नागरिकता"};

//This is where I get error, The line after this

    viewvdc = (TextView) findViewById(;
View rootView = inflater.inflate(R.layout.fragment_listview, container, false);
mspinner        = (Spinner) rootView.findViewById(;
//set adapter for spinner here
adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item,name);
// you can use getActivity() or this 

return rootView;
public void onItemSelected(AdapterView<?> parent, View view, int position,
    long id) {
    String selState = (String) mspinner.getSelectedItem();
    viewvdc.setText("Selected Android OS:" + selState);

public void onNothingSelected(AdapterView<?> arg0) {


I know this is a common mistake but i cant sort out

if viewvdc belongs to the activity you can use viewvdc = (TextView) getView().findViewById(;