I have a ListView adapter where by clicking on an item I want to show a dialog. For this, I created a class that shows a dialog with a button. By pressing a button on this dialog, I want to return the value to the adapter. How can i do this? Code example by clicking on a view in ListView

twoLineListItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final UserInformDialogAdd userInformDialogAdd = new UserInformDialogAdd(context); ArrayList<String> ll = userInformDialogAdd.get_add_user(); } }); 

Example of class UserInformDialogAdd

  public class UserInformDialogAdd { Context context; public UserInformDialogAdd(Context context) { this.context = context; } ArrayList<String> list; public ArrayList<String> get_add_user() { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); iew DialogView = inflater.inflate(com.akscorp.blueboard.R.layout.user_inform_dialog, null); AlertDialog.Builder builder; builder = new AlertDialog.Builder(context); builder.setView(DialogView); builder.setCancelable(true); builder.setPositiveButton("Добавить", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { list = что-то //тут бы как-то возвращать значение в адаптер } }); return add_used; } 

At the moment, it will naturally return null, because it will return the value before pressing the button, but how can we get the value by pressing?

  • one
    the adapter should not be engaged in such work, therefore you cannot find an acceptable solution. It is best to organize this functionality through the controller (activation or fragment) - pavlofff
  • Understood thanks. - Aksenov Vladimir

0