Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7733743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:04:48+00:00 2026-06-01T07:04:48+00:00

I have a custom dialog with one editText view and two buttons ok and

  • 0

I have a custom dialog with one editText view and two buttons ok and cancel. I have a custom list view displaying some rows of data fetched from database. When the user clicks on the row of the list view, custom dialog box is shown to the user to edit the selected row. What i want to do is to be able to pass the object binded with the selected row to the dialog box so that i could display the data being edited.

Here is my activity class:

public class TestDatabaseActivity extends ListActivity {
private CommentsDataSource datasource;
private CommentAdapter adt;

static final int CUSTOM_DIALOG_ID = 0;
private TextView dialog_editComment;
private EditText dialog_txtEditComment;
private Button dialog_btnOk, dialog_btnCancel;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    datasource = new CommentsDataSource(TestDatabaseActivity.this);
    datasource.open();
    getList();
}
private void getList()
{
    List<Comment> values = datasource.getAllComments();
    adt=new CommentAdapter(TestDatabaseActivity.this,R.layout.comment_row,values);
    setListAdapter(adt);    
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    CommentAdapter adapter= (CommentAdapter) getListAdapter();
    final Comment cmt = adapter.mListComment.get(position);
    System.out.println(cmt.getId()+cmt.getComment());

            //cmt is the object which i want to pass to my dialog
    showDialog(CUSTOM_DIALOG_ID);

}

   private Button.OnClickListener customDialog_UpdateOnClickListener = new Button.OnClickListener(){

 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  //save the value and update list
 }

   };

   private Button.OnClickListener customDialog_DismissOnClickListener
   = new Button.OnClickListener(){

 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  dismissDialog(CUSTOM_DIALOG_ID);
 }

   };

@Override
protected Dialog onCreateDialog(int id) {
 // TODO Auto-generated method stub
 Dialog dialog = null;;
    switch(id) {
    case CUSTOM_DIALOG_ID:
     dialog = new Dialog(TestDatabaseActivity.this);

     dialog.setContentView(R.layout.comment_edit_dialog);
     dialog.setTitle("Edit");

     dialog_editComment = (TextView)dialog.findViewById(R.id.editComment);
     dialog_txtEditComment = (EditText)dialog.findViewById(R.id.txtComment);
     dialog_btnOk = (Button)dialog.findViewById(R.id.btnOk);
     dialog_btnCancel = (Button)dialog.findViewById(R.id.btnCancel);

     dialog_btnOk.setOnClickListener(customDialog_UpdateOnClickListener);
     dialog_btnCancel.setOnClickListener(customDialog_DismissOnClickListener);
     break;
    }
    return dialog;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:04:49+00:00Added an answer on June 1, 2026 at 7:04 am

    Instead of using showDialog(CUSTOM_DIALOG_ID) use you can create a your own method with argument and in that you can use AlertDialog to display your view that contains textview and buttons.

    i)   private AlertDialog alert;   should be declared in class scope above oncreate().
    

    ii) Instead of showDialog(CUSTOM_DIALOG_ID) use createDialog(cmt)

    iii) private void createDialog(Comment cmt){
            AlertDialog.Builder dialog = new AlertDialog.Builder(TestDatabaseActivity.this);
            View view = _inflater.inflate(R.layout.comment_edit_dialog,null);
            dialog.setTitle("Edit");
    
            dialog_editComment = (TextView)view .findViewById(R.id.editComment);
            dialog_txtEditComment = (EditText)dialog.findViewById(R.id.txtComment);
            dialog_btnOk = (Button)view .findViewById(R.id.btnOk);
            dialog_btnCancel = (Button)view .findViewById(R.id.btnCancel);
    
            dialog_btnOk.setOnClickListener(customDialog_UpdateOnClickListener);
            dialog_btnCancel.setOnClickListener(customDialog_DismissOnClickListener);
            dialog.setView(view);
            //dialog.show();
            alert = dialog.create();
            alert.show();
        }
    

    iV) also instead of dismissDialog(CUSTOM_DIALOG_ID) use alert.dismiss();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom dialog, And I have inserted two buttons, one is
I have a custom Dialog that contains only a TextView to display some text
At the moment I have setup a custom ok cancel dialog with a drop
I have a custom Dialog that shows a few buttons. The idea is to
I have a custom dialog box that asks the user for some input. It's
I have created a custom dialog for Visual Studio Setup Project using the steps
I have a custom MFC dialog CMyDialog , with a custom control of type
In my installer I have set WixUIBannerBmp to point to my own custom dialog-banner.bmp
I have visual studio setup project with a custom RadioButtons dialog. How do I
I have a dialog that resizes. It also has a custom background which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.