我在带有OnItemClickListener和OnItemLongClickListener的ListView中遇到了问题。我用它们作为不同的活动。 Longclick打开用于编辑该项目的活动,并(短)单击打开sub itens活动。问题是,当用户长时间点击ListView项目时,它会启动正确的目标活动,但如果在目标活动打开后立即发布,我的应用程序会打开目标活动进行短暂点击,就像OnItemClickListener仍处于活动状态一样。 这是我的代码:
private void populateAvaliacoesListView(final long periodoId, final int selectedAvaliacoesOpen) {
ListAdapter adapter = new AvaliacoesListAdapter(this, R.layout._lst_avaliacoes_layout, allAvaliacoes);
Avaliacoes_lstAvaliacoes.setAdapter(adapter);
Avaliacoes_lstAvaliacoes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(mContext, Subitem_Activity.class);
startActivity(intent);
finish();
}
});
Avaliacoes_lstAvaliacoes.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(mContext, Edit_Activity.class);
startActivity(intent);
finish();
return false;
}
});
}