我的代碼在下面提到,不知道它有什麼問題。我在Fragment中有列表視圖,並且想要在點擊列表項目上調用活動。如何從點擊清單項目調用活動
public class fren_fragment extends Fragment {
FrenListAdapter cAdapter;
ListView cListView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.friend_fragment, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
cAdapter = new FrenListAdapter(getActivity());
cListView = (ListView) getActivity().findViewById(android.R.id.list);
cListView.setAdapter(cAdapter);
cListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
cListView.setItemChecked(position,true);
Context context = view.getContext();
Intent intent = new Intent(context, CompanyDetailActivity.class);
context.startActivity(intent);
}
});
}
}
取代'context'取代'getActivity()' –
你的問題在這裏很不明確,你能編輯它來描述你的具體問題嗎?它可能有助於閱讀[我如何問一個好問題?](http://stackoverflow.com/help/how-to-ask) – DaveyDaveDave
請確保你的'onItemClick'正在通過寫一些logcat來檢查它 –