问题描述
我有一个 FragmentActivity
控制一个 ListFragment
;该 ListFragment
包含一个通用的ListView
,适配器
,并提请一个的ArrayList
从辛格尔顿
,我创建的。
I have a FragmentActivity
that controls a ListFragment
; that ListFragment
contains a generic ListView
, Adapter
, and draws an ArrayList
from a Singleton
that I have created.
当在 onCreateView
方法我 ListFragment
我把下面的code:
When in the onCreateView
method of my ListFragment
I put the following code:
public View onCreateView(LayoutInflater viewInflation, ViewGroup container,
Bundle SavedInstantState) {
cycleviewfragment = viewInflation.inflate(
R.layout.cycleviewfragment_page, container, false);
context = getActivity().getApplicationContext();
Singleton mySingleton = Singleton.getInstance();
basicList = (ListView) cycleviewfragment.findViewById(android.R.id.list);
adapter = new ArrayAdapter<listControlObject>(getActivity()
.getApplicationContext(), android.R.layout.simple_list_item_1,
mySingleton.getA1());
this.setListAdapter(adapter);
addButton = (Button) cycleviewfragment.findViewById(R.id.addbutton);
addButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(getActivity(),
listaddactivity.class);
getActivity().startActivity(myIntent);
}
});
basicList.setOnItemClickListener(new ListView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Log.d("basicListtester", "Testing onClickItem call");
Intent myIntent = new Intent(getActivity(),
listdetailactivity.class);
myIntent.putExtra("selectedObjectIndex",arg2);
getActivity().startActivity(myIntent);
}
});
adapter.notifyDataSetChanged();
return cycleviewfragment;
}
任何想法,为什么当我将项目添加到我的名单,他们还没有反应过来的OnItemClick不叫?
Any ideas as to why when I add items to my list they do not react and the OnItemClick is not called?
谢谢你们。
[更新]
我试着用 basicList.setAdapter(适配器)实现它;
仍然没有工作
也试过有我的 ListFragment
实施 OnItemClickListener
和添加的方法的类;这也不起作用。
also tried having my ListFragment
implement OnItemClickListener
and added the method to the class; which did not work either.
推荐答案
由于您使用 ListFragment
你不应该设置 onItemClickListener
到列表中。目前已经在 ListFragment
的方法,你应该重写。
Since you use ListFragment
you shouldn't set onItemClickListener
to your list. There is already a method in ListFragment
that you should override.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
//Do your thingy.
}
这篇关于ListView控件,OnItemClick不会被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!