I am trying to add Alert Builder Inside a BaseAdapter under button clicked.
Here is my code
Button btn=(Button)vi.findViewById(R.id.btnAdd);
btn.setOnClickListener(new OnClickListener(){
AlertDialog.Builder dialogBox=new AlertDialog.Builder(this);
dialogBox.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
String facebookFriendName = friendsName.getText().toString();
String FACEBOOKID = FBID;
Log.i("AKO SI: ", ""+facebookFriendName + FACEBOOKID);
}
});
dialogBox.setNegativeButton("No", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
}
});
dialogBox.show();
Now I am getting an error on this part alert_box.show();
What seems to be the problem?
EDIT
based on your suggestion and comments I change my code above
and add a getter and setter on my Activity
private Context context;
/////////
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
Under my activity class under binding
adapter2 =new LazyAdapterGetFriends(this, songsList);
adapter2.getContext();
list.setAdapter(adapter2);
But I am still getting an error saying:
*09-11 13:48:49.298: E/AndroidRuntime(1226): at com.fb.connect.LazyAdapterGetFriends$1.onClick(LazyAdapterGetFriends.java:95)
*pointing at AlertDialog.Builder dialogBox=new AlertDialog.Builder(context);
try this
hope help
EDIT
try this.
AlertDialogs can only be created using Activity contexts, so getApplicationContext() will not work. Instead, add the following global variable to your Activity file:
And then add the following to your onCreate():
Now, change:
to