0

I have a ListView and I'm using SimpleCursorAdapter to populate the content, and newView & bindView to get the View.

I want to enable that everytime the button on the row list is clicked, it loads an AlertDialog box.

Here's the code:

btn.setOnClickListener(new OnClickListener() {
 public void onClick(View view) {
    Intent intent = getIntent();
    if (intent != null) {
    Uri uri = intent.getData();
    if (uri != null) {
    Cursor cursor = managedQuery(uri, new String[] {
    BaseColumns._ID, Database.Project.C_PRICE, Database.Project.C_KEYWORD,
    Database.Project.C_SHORTCODE}, null, null, null);

if (cursor == null) {
finish();
} else {
if (cursor.moveToFirst()) {

AlertDialog.Builder alertbox = new AlertDialog.Builder(this);                                             
alertbox.setTitle("SMS");

I always get an error on this line: AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

It says: The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined

how am I able to do that?

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
hectichavana
  • 1,436
  • 13
  • 41
  • 71

2 Answers2

4

You are using this to create the AlertDialog.Builder which is wrong use Activity_name.this. You are applying the button's listener's reference to create the AlertDialog.Builder rather you should have the reference of the Activity.

AlertDialog.Builder alertbox = new AlertDialog.Builder(Activity_name.this);
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
1

try this way

btn.setOnClickListener(new OnClickListener() {
     public void onClick(View view) {
         AlertDialog.Builder alertbox = new AlertDialog.Builder(view.getContext());
     }
}
Pratik
  • 30,639
  • 18
  • 84
  • 159