4
我在android中有一個AlertDialog,其中包含來自sqlite的好友列表。當我點擊列表中的好友名稱時,該好友被調用。我想要做的是將一個longclicklistener添加到列表中,以便我可以提示刪除列表中的好友。 onlclick和onlongclick在同一元素上工作時遇到問題。有人可以在這裏給我一個指針。我一直在使用android幾個月。謝謝你的幫助!以添加OnLongClickListenerAdd onlongclick listener to alertdialog
private void displayBuddyList(String region) {
final String region2 = region;
Context context = getApplicationContext();
dh = new DataBaseHelper(context);
List<String> bnames = dh.selectBuddies();
Log.d(TAG, "Buddy Names: " +bnames);
final CharSequence[] buds = bnames.toArray(new CharSequence[bnames.size()]);
// final CharSequence[] items = {"Mark", "Vikrant", "Olle,"Jane","Dan"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select a Buddy");
builder.setItems(buds, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int item) {
// showShortToast("Clicked on:"+buddy[item]);
String ptcode = buds[item].toString();;
if (region2 == "A") {
callbuddy(ptcode,region2);
} else if (region2 == "E") {
callbuddy(ptcode,region2);
} else if (region2 == "P") {
callbuddy(ptcode,region2);
} else {
showShortToast("We have a bug");
}
return;
}
});
builder.create().show();
}