how to return the visibility of ListFragment



  • All good hours of the day, when the program was written, I had a problem. ListFragment:

    public class PvPMap extends ListFragment{
    

    ListView map;
    FrameLayout fl;
    Fragment permafrost;
    Fragment river;
    Fragment reactor;
    Fragment oil;
    Fragment mountain;
    Fragment island;
    Fragment cold;
    Fragment pis;
    Fragment fire;
    Fragment air;

    FragmentManager manager;
    FragmentTransaction transaction;

    String [] mapname = new String[] {"Вечная мерзлота","Тихая река","Реактор","Нефтепровод","Предгорье",
    "Затеряный остров","Холодная сталь","Мирный рубеж","Горящий песок","Воздушная тревога"};
    int [] mapimg = new int[] {R.drawable.permafrost, R.drawable.river, R.drawable.reaktor, R.drawable.oil, R.drawable.mauntain,
    R.drawable.island, R.drawable.cold, R.drawable.pis, R.drawable.fire, R.drawable.air};

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View pvp = inflater.inflate(R.layout.layout_pvp, container, false);

    permafrost = new Permafrost();
    river = new River();
    reactor = new Reactor();
    oil = new Oil();
    mountain = new Mauntain();
    island = new Island();
    cold = new Cold();
    pis = new Pis();
    fire = new Fire();
    air = new Air();
    
    
    fl = (FrameLayout) pvp.findViewById(R.id.conteiner);
    map = (ListView) pvp.findViewById(android.R.id.list);
    
    
    List<HashMap<String, String>> aList =  new ArrayList<HashMap<String, String>>();
    
    for (int i = 0; i < mapname.length; i++){
        HashMap<String, String> m = new HashMap<String,String>();
        m.put("name", mapname[i]);            
        m.put("img", Integer.toString(mapimg[i]));
        aList.add(m);
    }
    
    String[] from = {"name", "img"};
    
    int [] to = {R.id.textViewMap, R.id.imageViewMap};
    
    SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.list_item, from, to);
    
    setListAdapter(adapter);
    
    return pvp;
    

    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    manager = getActivity().getSupportFragmentManager();
    transaction = manager.beginTransaction();

    switch (position){
        case 0:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, permafrost);
            transaction.addToBackStack(null);
            break;
        case 1:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, river);
            transaction.addToBackStack(null);
            break;
        case 2:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, reactor);
            transaction.addToBackStack(null);
            break;
        case 3:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, oil);
            transaction.addToBackStack(null);
            break;
        case 4:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, mountain);
            transaction.addToBackStack(null);
            break;
        case 5:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, island);
            transaction.addToBackStack(null);
            break;
        case 6:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, cold);
            transaction.addToBackStack(null);
            break;
        case 7:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, pis);
            transaction.addToBackStack(null);
            break;
        case 8:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, fire);
            transaction.addToBackStack(null);
            break;
        case 9:
            fl.setVisibility(View.VISIBLE);
            map.setVisibility(View.GONE);
            transaction.add(R.id.conteiner, air);
            transaction.addToBackStack(null);
            break;
    
    }
    transaction.commit();
    

    }

    I'm hiding. ListFragmentand the resulting fragment is visible, but the problem is when you press the buttons "Back" and get back to the bottom. ListFragment, he's still invisible until he leaves. acivity I won't come back again. How can this casus be resolved?

    XML-Fail

    <ListView android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:listSelector="@android:color/transparent"/>
    

    <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/conteiner"
    android:visibility="gone"/>



  • Use new fragments to display. transaction.add()transaction.replace() - Then you won't have to hide a piece of the list because there will be a replacement of fragments, not an addition to the existing one. The "bad" button will work correctly.

    I mean, the cabins will take about this type:

        case 0:
            transaction.replace(R.id.conteiner, permafrost);
            transaction.addToBackStack(null);
            break;
    

    It's very desirable to read. http://developer-android.unlimited-translate.org/training/basics/fragments/fragment-ui.html on the subject, in particular http://developer-android.unlimited-translate.org/training/basics/fragments/fragment-ui.html#Replace ♪


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2