我的代码在下面提到,并且不知道它有什么问题。我在Fragment中有列表视图,想在点击列表项上调用活动。
foreach ($keywords as $key=>$keyword){
if(strlen($keyword) > 3){
$where .= "keywords LIKE '%$keyword%'";
if ($key != ($total_keywords - 1))
$where .= " OR ";
}
}
答案 0 :(得分:1)
试试这个:
cListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
cListView.setItemChecked(position, true);
Intent intent = new Intent(getActivity(), CompanyDetailActivity.class);
getActivity().startActivity(intent);
}
});
答案 1 :(得分:0)
你应该改变
Context context = view.getContext();
Intent intent = new Intent(context, CompanyDetailActivity.class);
context.startActivity(intent);
到
Intent intent = new Intent(getActivity(), CompanyDetailActivity.class);
startActivity(intent);
答案 2 :(得分:0)
Context
的{{1}}错误,请尝试此操作。
Intent
答案 3 :(得分:0)
试试这个:
Intent intent = new Intent(getActivity(), CompanyDetailActivity.class);
startActivity(intent);
答案 4 :(得分:0)
更改您的代码如下
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.friend_fragment, container, false);
cAdapter = new FrenListAdapter(getActivity());
cListView = (ListView) view.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);
Intent intent = new Intent(getActivity(), CompanyDetailActivity.class);
getActivity().startActivity(intent);
}
});
}
删除
@Override
public void onActivityCreated(Bundle savedInstanceState) {
}