2016-08-16 88 views
0

得到錯誤使用 「this」 在fragement的時候,而不是我能use.Below什麼是給定的代碼:得到錯誤,而使用 「這個」

public class Tab1 extends Fragment { 
private List<DataJobs> datajobs = new ArrayList<>(); 
private RecyclerView recyclerView; 
private EventsAdapter mAdapter; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.tab_1, container, false); 
    return rootView; 
    recyclerView = (RecyclerView)getView().findViewById(R.id.recycler_view); 

    mAdapter = new EventsAdapter(datajobs); 

    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext()); 
    recyclerView.setLayoutManager(mLayoutManager); 
    recyclerView.addItemDecoration(new DividerItemDecoration(**this**, LinearLayoutManager.VERTICAL)); 
    recyclerView.setItemAnimator(new DefaultItemAnimator()); 

    recyclerView.setAdapter(mAdapter); 

    prepareMovieData(); 
} 
+0

你會得到什麼樣的錯誤? –

+0

DividerItemDecoration(android.content.Context,int)不能應用於DividerItemDecoration(tabs.Tab1,int) – tiya

回答

0

使用getActivity()代替

recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));