Je suis confronté à ce problème uniquement dans moto g 2ème génération. Ce code fonctionne parfaitement sur d'autres appareils.OnClick est appelé à la place de onLongClick
J'ai mis en œuvre onClick
et onLongClick
adaptateur intérieur sur des articles de lisview. Mais lorsque je clique longtemps sur un élément, onClick est appelé à la place de onLongClick. OnClick est également appelé si je fais défiler la liste lentement.
code à l'intérieur getView()
est ci-dessous:
LayoutInflater inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
lifeActionObj = actionList.get(position);
View v = (View)inflater.inflate(R.layout.single_action, null);
TextView actionNameView = (TextView) v.findViewById(R.id.action_name);
ImageView actionIcon = (ImageView) v.findViewById(R.id.action_icon);
final Button aInfoBtn = (Button) v.findViewById(R.id.action_info);
final Button aPickBtn = (Button) v.findViewById(R.id.action_pick);
final int actionLocked = lifeActionObj.isLocked();
aPickBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(actionLocked ==1)
{
diplayDialog();
}
else
{
LifeUser lifeUser = new LifeUser();
try {
LifeAction lifeActionObj = actionList.get(position);
int result = lifeUser.addHabit(traitId, lifeActionObj);
} catch (Exception e1) {
e1.printStackTrace();
}
actionActivity.finish();
}
}
});
aInfoBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(actionLocked ==1)
{
diplayDialog();
}
else
{
Intent in = new Intent(actionActivity,
DisplayHtmlActivity.class);
try
{
in.putExtra("title", actionList.get(position).getDisplayName());
in.putExtra("fileName", actionList.get(position).getActionInfoFileName(actionActivity.getLifeTraitObject().getTraitId())+".html");
}
catch (Exception e)
{
e.printStackTrace();
}
actionActivity.startActivity(in);
}
}
});
final ViewGroup parent1 = parent;
final View ex = v;
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(actionActivity, "on click", Toast.LENGTH_SHORT).show();
if(actionActivity.getActionMode() != null)
{
actionActivity.getActionMode().finish();
}
if(actionLocked == 1)
{
diplayDialog();
}
}
});
v.setOnLongClickListener(new OnLongClickListener()
{
@Override
public boolean onLongClick(View v) {
Toast.makeText(actionActivity, "on long click", Toast.LENGTH_SHORT).show();
if(actionLocked == 1)
{
return false;
}
else
{
ex.setBackgroundColor(Color.LTGRAY);
ex.setLongClickable(false);
ex.setClickable(false);
parent1.setClickable(false);
aInfoBtn.setClickable(false);
aPickBtn.setClickable(false);
final int traitPosition = position;
try {
actionActivity.startActionMode(new LifeCAB(
ex,
parent1,
traitPosition,
aInfoBtn,
aPickBtn,
actionList.get(position).getDisplayName()));
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
});
return v;
Quelqu'un peut-il me dire ce qui peut être la cause de cela? Merci de me guider pour résoudre ce problème.
Je ne trouve pas de changement. Le code ci-dessus renvoie également vrai. Aussi ce code ne fonctionne pas seulement pour moto g 2ème génération. – megha