2015-04-25 51 views
1

我有一個ListView,我已經把一個onClickListener它。當我點擊它時,它應該運行一個AlertDialog,但它似乎不起作用。 AlertDialog應該顯示ListView中的一些字符串。這裏是我使用的代碼。AlertDialog無法加載

listView.setOnItemClickListener(new OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
            int position, long id) { 
       PopUpAlert(id); 

      } 
     }); 


private void PopUpAlert(final long id) { 

      Cursor cursor = dbHelper.getAllReviewRows(id); 

      if (cursor.moveToFirst()) { 

       //Preparing variables to use in message from Establishment record in Database 

       final String SName = cursor.getString(dbHelper.COL_REV_STATION_NAME); 
       String Date = cursor.getString(SQL.COL_DATE); 
       String SFacility = cursor.getString(SQL.COL_REV_FACILITY); 
       String Rating = cursor.getString(SQL.COL_RATING); 
       String Comment = cursor.getString(SQL.COL_COMMENTS); 

       // building a drill down information message and displaying it in an Alert Dialog 
       new AlertDialog.Builder(this) 
         .setTitle("Facilities Review App") 
         .setMessage("You Selected:\n" 
           + "Station Name: " + SName + "\n" + "Date: " + Date 
           + "\n" + "Facility: " + SFacility + "\n" + "Rating: " + Rating 
           + "\n" + "Comment: " + Comment) 
         .setPositiveButton("Add Image", new DialogInterface.OnClickListener() { 

          @Override 
          public void onClick(DialogInterface dialog, int which) { 
           // calling method to add a review for that particular establishment 
           addImage(SName); 

          } 
         }) 
         .setNegativeButton("Delete", new DialogInterface.OnClickListener() { 

          @Override 
          public void onClick(DialogInterface dialog, int which) { 
           // calling method to delete that particular establishment 


          } 


         }); 

      } 

     } 

回答

2

你沒有在你的AlertDialog致電show()

new AlertDialog.Builder(this) 
.setTitle("Facilities Review App") 
.setMessage("...") 
.setPositiveButton(..) 
.setNegativeButton(..) 
.show(); 

在這裏你可以找到文檔AlertDialog.Builder.show()

+0

好吧,我把它和它的工作。謝了哥們 – D4rkH34rt