Avoid overlapping of Listview

Asked

Viewed 91 times

2

I have a problem with ListViewI work with 2 ListViewAnd I want that when I click one, that the other disappears and that they don’t overlap as they have been. I just want when I click and open the first ListView and then right before if I click to open the second ListView, that the first one closes.

The code I am using is this and can also be seen by the following image:

    switch (v.getId()) {
        case R.id.like:

            preecheListLike();

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

                    String nome = listaLike.getItemAtPosition(position).toString();

                    setMarker(latit, longi, nome, true, position);
                    listaLike.setVisibility(View.INVISIBLE);
                    setUpMap();
                }

            });

            break;
        case R.id.dislike:

            preecheListDislike();
            listaDislike.setVisibility(View.VISIBLE);
            //listaLike.setVisibility(View.INVISIBLE);
            listaDislike.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    String nome = listaDislike.getItemAtPosition(position).toString();

                    setMarker(latit, longi, nome, false, position);
                    listaDislike.setVisibility(View.INVISIBLE);
                    setUpMap();
                }
            });
            break;
        case R.id.rota:
            //AQUI ATIVA O BOTAO CALCULAR ROTA
            //showDist.setVisibility(View.VISIBLE);
            calcRout.setVisibility(View.VISIBLE);
            yourDest.setVisibility(View.VISIBLE);

        break;


    }

}

Image illustrating the problem:

Imagem

  • Welcome to the Stackoverflow! It is not very clear your doubt, especially at this point: "[...] I want when I click on one other sum and not be superimposed as it has been [...]". We don’t know your application Alezinha, it’s important that you give more details about what’s going on (and if possible what you’ve already tried). It might help to post an image illustrating what you meant by this "overlap". See how ask a good question.

  • Thanks for the tips, I did a print to illustrate the "problem"

  • IMAGE TO ILLUSTRATE THE PROBLEM: http://i58.tinypic.com/105t7jd.jpg

  • You left commented the line that hides Listview, is it not working? You even tried to change the visibility with the flag View.GONE?

  • Wakim, if I do not comment any listview opens, however if I comment, it looks like in the image I left a link up there. I just wanted to fix it so when someone click on a listview.

  • Strange because they are different lists... Do listaLikes.setVisibility(View.VISIBLE); and listaDislikes.setVisibility(View.VISIBLE); should work. Because you are changing the visibility of different lists. You can tell if the two references do not point to the same object?

  • I just checked and the two lists do not point to the same object. :/

  • Could you put the layout? If you are using the FrameLayout I think I had problems with visibility. But in the case I used some animations, which caused the problem, and a clearAnimation ended up solving the visibility problem.

  • I managed to solve it in a kind of rough way, with only one boolean variable :)

  • @Alezinha, please, post your solution.

Show 5 more comments

1 answer

1

In my view they are superimposed because by default when you do not put the visibility in the layout becomes as VISIBLE.

From what I’ve analyzed of your logic you will only alter the visibility when you go through switch (v.getId())

Another tip is to use the View.GONE that @Wakim commented on, as the INVISIBLE only hides the content, but keeps the view space allocated, already the GONE will clean and clear the space for that other View can use. For more information View

Browser other questions tagged

You are not signed in. Login or sign up in order to post.