在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;
}
任何示例程序都将受到赞赏
答案 0 :(得分:0)
如果您在列表视图中使用任何布局,请使用...
android:descendantFocusability="blocksDescendants"
必须应用于列表中的第一个父级。它将呈现单击列表项。
答案 1 :(得分:0)
尝试在onItemLongClick而不是true
var newTable = request.responseXML.documentElement.getElementsByTagName('table');