How to close a pop up list view after selecting an item in Android

Dispatcher

Trying to close a list view after I click on an item. The listview pops up with a list of items and after i click on an item, it stays there. Is there a sort of similar thing to dialog.dismiss() or something for listviews?

     final ListView lvUser = new ListView(this);
    userList = tmDB.getAllUsers();
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.selectUser);
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, userList);
    lvUser.setAdapter(arrayAdapter);
    builder.setView(lvUser);

    //when user selects item
    lvUser.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String name = userList.get(position);
            int userID;
            userID = tmDB.getUserId(name);
            txtName.setText(name);
// close the list view after selecting an item
        }
    });
Raja

You have to use like

 public AlertDialog alertDialog;

        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.selectUser);
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(Main3Activity.this, android.R.layout.simple_list_item_1, userList);
        lvUser.setAdapter(arrayAdapter);
        builder.setView(lvUser);

        //when user selects item
        lvUser.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String name = userList.get(position);
                int userID;
                userID = tmDB.getUserId(name);
                txtName.setText(name);
// close the list view after selecting an item
                alertDialog.dismiss();

            }
        });

        alertDialog = builder.create();
        alertDialog.show();

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

App auto closes after selecting list view item

分類Dev

how to close pop up modal window in the bootstrap

分類Dev

How to remove list view item in list view android?

分類Dev

How To: Have 2 seperate buttons to close modal pop up?

分類Dev

How to display text for an item in a list view Android Studio

分類Dev

How to have the pop-up window for method definition in intelliJ while selecting the methods available?

分類Dev

Item List Layout showing up in Android Studio, but not in Emulator

分類Dev

Close the pop-up menu when user reach the bottom of the page

分類Dev

How to set Select component in Material-UI to loose its focus state after selecting one of its item

分類Dev

How to update list item in firebase using android

分類Dev

Google-map-react - reactjs: How to dynamically show pop-up window after clicking on a marker

分類Dev

How to populate a GridView in a pop-up that is inside an UpdatePanel after a button click inside an UpdatePanel

分類Dev

How to delete an item of a list from another view in SwiftUI?

分類Dev

Android Firebase push notification automatic pop up

分類Dev

Android: How to maintain set data in the list view

分類Dev

how do I add a checkbox before every list Item, and a delete button after the list item?

分類Dev

How to make list item overflow scroll horizontally after 6 list item?

分類Dev

How to show the selected listview item with image and text on bottom (Android View)

分類Dev

TornadoFX with TestFX close the View after every TestCase

分類Dev

How to use hexo to pop up a picture

分類Dev

How to open pop up via code

分類Dev

How to make this pop up layer in the middle of the page?

分類Dev

How can i use espresso to click an item from a list view based on item' text?

分類Dev

File not found error after selecting a file in android

分類Dev

SwiftUI - picker is having freezing when selecting after keyboard is up

分類Dev

How do I dynamically add a background view to Recycler list view item?

分類Dev

Returning the deleted item after using array_pop

分類Dev

Selecting an item with multiple conditions from a list using Espresso

分類Dev

Selecting respective item in drop down list when edit button is clicked

Related 関連記事

  1. 1

    App auto closes after selecting list view item

  2. 2

    how to close pop up modal window in the bootstrap

  3. 3

    How to remove list view item in list view android?

  4. 4

    How To: Have 2 seperate buttons to close modal pop up?

  5. 5

    How to display text for an item in a list view Android Studio

  6. 6

    How to have the pop-up window for method definition in intelliJ while selecting the methods available?

  7. 7

    Item List Layout showing up in Android Studio, but not in Emulator

  8. 8

    Close the pop-up menu when user reach the bottom of the page

  9. 9

    How to set Select component in Material-UI to loose its focus state after selecting one of its item

  10. 10

    How to update list item in firebase using android

  11. 11

    Google-map-react - reactjs: How to dynamically show pop-up window after clicking on a marker

  12. 12

    How to populate a GridView in a pop-up that is inside an UpdatePanel after a button click inside an UpdatePanel

  13. 13

    How to delete an item of a list from another view in SwiftUI?

  14. 14

    Android Firebase push notification automatic pop up

  15. 15

    Android: How to maintain set data in the list view

  16. 16

    how do I add a checkbox before every list Item, and a delete button after the list item?

  17. 17

    How to make list item overflow scroll horizontally after 6 list item?

  18. 18

    How to show the selected listview item with image and text on bottom (Android View)

  19. 19

    TornadoFX with TestFX close the View after every TestCase

  20. 20

    How to use hexo to pop up a picture

  21. 21

    How to open pop up via code

  22. 22

    How to make this pop up layer in the middle of the page?

  23. 23

    How can i use espresso to click an item from a list view based on item' text?

  24. 24

    File not found error after selecting a file in android

  25. 25

    SwiftUI - picker is having freezing when selecting after keyboard is up

  26. 26

    How do I dynamically add a background view to Recycler list view item?

  27. 27

    Returning the deleted item after using array_pop

  28. 28

    Selecting an item with multiple conditions from a list using Espresso

  29. 29

    Selecting respective item in drop down list when edit button is clicked

ホットタグ

アーカイブ