Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android

Respuesta
 
Herramientas
  #1  
Viejo 23/06/17, 08:44:40
Array

[xs_avatar]
Merche300 Merche300 no está en línea
Betatester oficial
 
Fecha de registro: dic 2008
Localización: Valencia
Mensajes: 625
Modelo de smartphone: NEXUS 5 - ONEPLUS 3
Tu operador: Pepephone
SearchView

Tengo un problema, que ya no se ni por donde mirar, el caso es que cada vez que abro este TabLayout o este fragment, no se donde estara el error,se me agrega una lupa a la toobar, ¿Como lo puedo arreglar?

Código:
public class Tab_Ïnicio extends Fragment {
    private AppBarLayout appBar;
    private TabLayout pestanas;
    private ViewPager viewPager;

    public Tab_Ïnicio() {
    }

    [COLOR=#808000 @override
[/color]public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragmento_paginado, container, false);

        if (savedInstanceState == null) {
            insertarTabs(container);

            // Setear adaptador al viewpager.
viewPager = (ViewPager) view.findViewById(R.id.pager);
            poblarViewPager(viewPager);
            pestanas.setupWithViewPager(viewPager);


            pestanas.setTabGravity(TabLayout.GRAVITY_CENTER);
            pestanas.setTabMode(TabLayout.MODE_FIXED);
            //pestanas.setTabMode(TabLayout.MODE_SCROLLABLE);
}

        return view;
    }

    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.menu_main, menu);
        super.onDestroyView();
    }


    private void insertarTabs(ViewGroup container) {
        View padre = (View) container.getParent();
        appBar = (AppBarLayout) padre.findViewById(R.id.appbar);
        pestanas = new TabLayout(getActivity());
        pestanas.setTabTextColors(Color.parseColor("#FFFFFF"), Color.parseColor("#FFFFFF"));
        appBar.addView(pestanas);
    }

    private void poblarViewPager(ViewPager viewPager) {
        AdaptadorSecciones adapter = new AdaptadorSecciones(getFragmentManager());

        adapter.addFragment(new FragGridCampos(), ("Todos"));
        adapter.addFragment(new FragGridComentarios(), ("Comentarios"));
        viewPager.setAdapter(adapter);
    }

    [COLOR=#808000 @override
[/color]public void onDestroyView() {
        super.onDestroyView();
        appBar.removeView(pestanas);
    }

    /**
     * Un {@link FragmentStatePagerAdapter} que gestiona las secciones, fragmentos y
     * títulos de las pestañas
     */
public class AdaptadorSecciones extends FragmentStatePagerAdapter {
        private final List<Fragment> fragmentos = new ArrayList<>();
        private final List<String> titulosFragmentos = new ArrayList<>();

        public AdaptadorSecciones(FragmentManager fm) {
            super(fm);
        }

        [COLOR=#808000 @override
[/color]public Fragment getItem(int position) {
            return fragmentos.get(position);
        }

        [COLOR=#808000 @override
[/color]public int getCount() {
            return fragmentos.size();
        }

        public void addFragment(Fragment fragment, String title) {
            fragmentos.add(fragment);
            titulosFragmentos.add(title);
        }

        [COLOR=#808000 @override
[/color]public CharSequence getPageTitle(int position) {
            return titulosFragmentos.get(position);
        }
    }
}

O en este?

Código:
public class FragGridCampos extends Fragment implements SearchView.OnQueryTextListener{

    //Creating a List of jornadas
private List<Estadisticas> listJornadas;

    //Creating Views
private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private Campos_Adapter adapter;


    private List<Estadisticas> mCountryModel;


    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate( R.layout.campos_list, null);

        setHasOptionsMenu(true);

        recyclerView = (RecyclerView) view.findViewById( R.id.recyclerView);
        recyclerView.setHasFixedSize(true);
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), 1);
        recyclerView.setLayoutManager(layoutManager);

        TextView miTexto = (TextView)view.findViewById( R.id.mi_texto);
        miTexto.setText("CAMPOS");
        //miTexto.setTextColor(color.RED);
listJornadas = new ArrayList<Estadisticas>();

        adapter = new Campos_Adapter(listJornadas, getActivity());
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new DecoracionLineaDivisoria(getActivity()));

        getData();

        /*ImageButton fabButton = (ImageButton) view.findViewById(R.id.fab);
        fabButton.setOnClickListener(new View.OnClickListener() {
            @override
            public void onClick(View v) {
                //startActivity(new Intent(getActivity(), MainActivity2.class));
                Toast.makeText(getActivity(),"Proximamente",Toast.LENGTH_SHORT).show();
            }
        });*/
return view;
    }

    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.menu_buscar, menu);
        super.onDestroyView();
        final MenuItem searchItem = menu.findItem(R.id.action_search);
        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setOnQueryTextListener(this);


    }

    //This method will get data from the web api
private void getData(){
        //Showing a progress dialog
final ProgressDialog loading = ProgressDialog.show(getActivity(),"Cargando datos", "Por favor espere...",false,false);

        //Creating a json array request
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Config_Url.CAMPOS,
                new Response.Listener<JSONArray>() {
                    [COLOR=#808000 @override
[/color]public void onResponse(JSONArray response) {
                        //Dismissing progress dialog
loading.dismiss();

                        //calling method to parse json array
parseData(response);
                    }
                },
                new Response.ErrorListener() {
                    [COLOR=#808000 @override
[/color]public void onErrorResponse(VolleyError error) {

                    }
                });

        //Creating request queue
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());

        //Adding request to the queue
requestQueue.add(jsonArrayRequest);
    }

    //This method will parse json data
private void parseData(JSONArray array){

        for(int i = 0; i<array.length(); i++) {
            Estadisticas campo = new Estadisticas();
            JSONObject json = null;
            try {
                json = array.getJSONObject(i);

                campo.setNombre_campo(json.getString("nombre_campo"));
                campo.setPoblacion(json.getString("poblacion"));
                campo.setEquipo(json.getString("equipo"));
                campo.setTelefono(json.getString("telefono"));
                campo.setGeo(json.getString("geo"));
                campo.setUrl(json.getString("url"));
                campo.setEmail(json.getString("email"));

                campo.setEscudo("http://juveniles.esy.es/Escudos/" + json.getString("escudo"));

            } catch (JSONException e) {
                e.printStackTrace();
            }
            listJornadas.add(campo);
            adapter.notifyDataSetChanged();
        }
    }

    [COLOR=#808000 @override
[/color]public boolean onQueryTextChange(String newText) {
        final List<Estadisticas> filteredModelList = filter(listJornadas, newText);

        adapter.setFilter(filteredModelList);
        return true;
    }

    [COLOR=#808000 @override
[/color]public boolean onQueryTextSubmit(String query) {
        return false;
    }

    private List<Estadisticas> filter(List<Estadisticas> models, String query) {
        query = query.toLowerCase();
        final List<Estadisticas> filteredModelList = new ArrayList<>();
        for (Estadisticas model : models) {
            final String poblacion = model.getPoblacion().toLowerCase();
            final String equipo = model.getEquipo().toLowerCase();

            if (poblacion.contains(query)) {
                filteredModelList.add(model);
            }
            else if (equipo.contains(query)) {
                filteredModelList.add(model);
            }
        }
        return filteredModelList;

    }
}

Última edición por Merche300 Día 08/07/17 a las 22:31:29.
Responder Con Cita


  #2  
Viejo 23/06/17, 15:15:05
Array

[xs_avatar]
Merche300 Merche300 no está en línea
Betatester oficial
 
Fecha de registro: dic 2008
Localización: Valencia
Mensajes: 625
Modelo de smartphone: NEXUS 5 - ONEPLUS 3
Tu operador: Pepephone
La solucion:

Código:
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    menu.clear();
    inflater.inflate(R.menu.menu_buscar, menu);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
}
Responder Con Cita
Respuesta

Estás aquí
Regresar   Portal | Indice > Todo sobre Android > Programación y Desarrollo para Android



Hora actual: 03:10:06 (GMT +2)



User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.

Contactar por correo / Contact by mail / 邮件联系 /