I wrote the following code but it only works for first 3 list items and for the remaining it raises null pointer exception.
list.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,final int arg2, long arg3) {
// TODO Auto-generated method stub
for(int i = 0; i <=list.getLastVisiblePosition(); i++)
{
System.out.println("onItemLongClick"+i);
if(i==arg2)
{
(list.getChildAt(i).findViewById(R.id.mark)).setVisibility(View.VISIBLE);
(list.getChildAt(i).findViewById(R.id.deleteitem)).setVisibility(View.VISIBLE);
}
else{
(list.getChildAt(i).findViewById(R.id.mark)).setVisibility(View.GONE);
(list.getChildAt(i).findViewById(R.id.deleteitem)).setVisibility(View.GONE);
}
}
(list.getChildAt(arg2).findViewById(R.id.deleteitem)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(AllMessagesActivity.this, "Delete at" +arg2, Toast.LENGTH_LONG).show();
}
});
(list.getChildAt(arg2).findViewById(R.id.mark)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(AllMessagesActivity.this, "Mark Spam at" +arg2, Toast.LENGTH_LONG).show();
}
});
return false;
}
});
In the list item only one text item and two buttons. When I click on one list item then only the two buttons of that item has to visible and the remaining list item buttons should not visible. And when you click other list item then the previous selected item buttons also disable. The above code works only for the first 3 items of list but it is not working for all.
Thank you in advance.