在listView onItemLongClick
中被触发,但 onItemClick
并未触发。我希望onItemClick
和onItemLongClick
触发。
onItemClick
将调用项目详细活动
onItemLongClick
将喜欢项目
这是我的代码:
public class myClass extends ListFragment implements OnItemClickListener ,OnItemLongClickListener
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//System.out.println("<<<<<<<<<<<<<<<<<<<<Boy in onCreateView>>>>>>>>>>>>>>>>>>>>");
View v = inflater.inflate(R.layout.boy, container, false);
lvBNames = (ListView) v.findViewById(android.R.id.list);
searchView = (SearchView) v.findViewById(R.id.action_search);
if (searchView == null )
{
//System.out.println("Unable to instantiate");
}
pop_data();
adapter = new ListBNamesAdapter(getActivity(),mBNamesList);
lvBNames.setSmoothScrollbarEnabled(false); //android:smoothScrollbar="true"
lvBNames.setAdapter(adapter);
//lvBNames.setOnItemClickListener(this);
//lvBNames.setOnItemLongClickListener(this);
//////////////////////////////////////// Test 28 Feb 17
/// onItemClick is not triggering ............!
lvBNames.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(activity, "Click", Toast.LENGTH_SHORT).show();
}
});
/// setOnItemLongClickListener is triggering ............! :)
lvBNames.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(activity, "Long Click", Toast.LENGTH_SHORT).show();
return true;
}
});
lvBNames.setTextFilterEnabled(true);
return v;
}
任何示例程序都将不胜感激
如果您在列表视图中使用任何布局,则使用...
android:descendantFocusability="blocksDescendants"
必须应用于列表中的第一父母。它将单击列表项目。
尝试在OnItemlongClick中返回false
,而不是true