我正在尝试OnItemClickListener
在 a 中使用方法,ListView
但它没有被调用,因为它ViewPager
拦截了触摸事件。
我试过了
mPager.requestDisallowInterceptTouchEvent(false);
在我的FragmentActivity
, 和
lista.setDescendantFocusability(ListView.FOCUS_BLOCK_DESCENDANTS);
在我的 onCreate 方法中,ListFragment
但没有任何反应。(“lista”是我的ListView
)。
这是OnItemClickListener
方法代码:
lista = (ListView) view.findViewById(id.list);
lista.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//It's not being called
}
});
几天前,我只使用Activities
而不是Fragments
(现在我需要它们,因为ViewPager
)并且代码运行良好,所以我认为不需要 xml。
编辑添加更多代码:
片段活动
public class TabsFacturasActivity extends SherlockFragmentActivity {
private static class MyAdapter extends FragmentPagerAdapter {
private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" };
private final FragmentManager mFragmentManager;
private Fragment mFragmentAtPos0;
public MyAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
mFragmentManager = fragmentManager;
}
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0: // Fragment # 0
return new FacturasFragment();
...
}
return null;
}
@Override
public int getCount() {
return titles.length;
}
@Override
public int getItemPosition(Object object)
{
if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment)
return POSITION_NONE;
return POSITION_UNCHANGED;
}
}
列表片段
public class FacturasFragment extends ListFragment {
private ListView lista;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.activity_facturas, container, false);
...
lista = (ListView) view.findViewById(id.list);
lista.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//It's not being called
}
});
return view;
}
}