Android点击后刷新LinearLayout

时间:2016-07-26 05:39:17

标签: android button refresh android-linearlayout

如何刷新名为" contNoticias"的LinearLayout?点击按钮后?

这是我的代码:

contNoticias = (LinearLayout)findViewById(R.id.contNoticias);

    int arrayNoticias = 1;
    for (int i = 0; i < arrayNoticias; i++) {
        //agregar views
        RelativeLayout relativeLayout = new RelativeLayout(antro.this);
        relativeLayout.setPadding(0, 0, 0, 0);
        relativeLayout.setId(+1);
        contNoticias.addView(relativeLayout);
        relativeLayout.setBackgroundResource(R.drawable.textviews_menu);

        //Separar variables
        try {
            httpHandler handler = new httpHandler();
            String response = handler.post(url + "MyDayFiles/muro.php");
            JSONArray array = new JSONArray(response);

            for (int u = 0; u < array.length(); u++) {
                JSONObject jsonObject = array.getJSONObject(u);

                tituloN += jsonObject.getString("nombre") + "/";
                tituloN = tituloN.replace("null", "");
                titulosN = tituloN.split("/");

                noticiaN += jsonObject.getString("noticia") + "/";
                noticiaN = noticiaN.replace("null", "");
                noticiasN = noticiaN.split("/");

                imagenN += jsonObject.getString("foto") + "/";
                imagenN = imagenN.replace("null", "");
                imagenesN = imagenN.split("/");
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        //imagen
        ImageView imagenNoticia = new ImageView(antro.this);
        imagenNoticia.setId(+2);
        RelativeLayout.LayoutParams imagenNoticiaParams = new RelativeLayout.LayoutParams(250, 250);
        imagenNoticiaParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        imagenNoticiaParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        imagenNoticiaParams.addRule(RelativeLayout.ALIGN_PARENT_START);
        imagenNoticia.setLayoutParams(imagenNoticiaParams);
        imagenNoticia.setScaleType(ImageView.ScaleType.CENTER_CROP);

        Picasso.with(this).load(url + "MyDayFiles/imgnoticias/" + imagenesN[i]).into(imagenNoticia);
        //imagen

        //titulo
        TextView tituloNoticia = new TextView(antro.this);
        tituloNoticia.setId(+3);
        RelativeLayout.LayoutParams tituloNoticiaParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        tituloNoticiaParams.addRule(RelativeLayout.RIGHT_OF, imagenNoticia.getId());
        tituloNoticia.setLayoutParams(tituloNoticiaParams);
        tituloNoticia.setTextColor(Color.DKGRAY);
        tituloNoticia.setTextSize(12);
        tituloNoticia.setPadding(20, 0, 0, 0);
        tituloNoticia.setText(titulosN[i]);
        //titulo

        //noticia
        TextView textoNoticia = new TextView(antro.this);
        textoNoticia.setId(+4);
        RelativeLayout.LayoutParams textoNoticiaParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        textoNoticiaParams.addRule(RelativeLayout.BELOW, tituloNoticia.getId());
        textoNoticiaParams.addRule(RelativeLayout.RIGHT_OF, imagenNoticia.getId());
        textoNoticia.setLayoutParams(textoNoticiaParams);
        textoNoticia.setTextColor(Color.GRAY);
        textoNoticia.setTextSize(12);
        textoNoticia.setPadding(20, 0, 0, 0);
        textoNoticia.setText(noticiasN[i]);
        //noticia

        //agregar views
        relativeLayout.addView(imagenNoticia);
        relativeLayout.addView(tituloNoticia);
        relativeLayout.addView(textoNoticia);

    }

当用户点击按钮时,我想刷新LinearLayout中的视图&#34; Post&#34;因此,当用户点击按钮时,新帖子可以显示在屏幕上

0 个答案:

没有答案