Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6609775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:45:27+00:00 2026-05-25T19:45:27+00:00

I have a problem with a textview in android. I made programatically a tablelayout,

  • 0

I have a problem with a textview in android.

I made programatically a tablelayout, and i made 9 tablerows in a for (while i have data… make more tablerows). I have 8 columns with data, thats ok. But i have 3 columns that i want to put invisible, because i want data from that textviews but i dont want to see them in my layout. Here i put my code, i dont know why textview.setVisibility(View.GONE) doesn’t works.. I put view.gone and in my table appears a black space in my layout (my table background color is black), any help?

here is the code

public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

TableLayout tl = (TableLayout) findViewById(R.id.tabla1);

       tl.setStretchAllColumns(true);  
       tl.setShrinkAllColumns(true);



       //------------------------------------------------------
       //seteo la fila para el Titulo

       TableRow rowTitulo = new TableRow(this);  
       rowTitulo.setGravity(Gravity.CENTER_HORIZONTAL);


        TextView titulo = new TextView(this);  
        titulo.setText("Operativa SHAMAN");
        titulo.setTextColor(Color.GREEN);

        titulo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);  
        titulo.setGravity(Gravity.CENTER);  
        titulo.setTypeface(Typeface.SERIF, Typeface.BOLD); 
        titulo.setVisibility(4);

        TableRow.LayoutParams params = new TableRow.LayoutParams();  
        params.span = 8;  

        rowTitulo.addView(titulo, params);  


        tl.addView(rowTitulo);


        //--------------------------------------------------------


       //seteo los titulos de los campos

       TableRow rowCampos = new TableRow(this);  

       TextView codServ = new TextView(this);
       TextView codEnt = new TextView(this);
       TextView incid = new TextView(this);
       TextView sint = new TextView(this);
       TextView codLoc = new TextView(this);
       TextView numMovil = new TextView(this);
       TextView sexEdad = new TextView(this);
       TextView estMovil = new TextView(this);

       codServ.setTextColor(Color.BLACK);
       codServ.setText("GR");
       codServ.setGravity(Gravity.CENTER);
       rowCampos.addView(codServ);

       codEnt.setTextColor(Color.BLACK);
       codEnt.setText("Entidad");
       codEnt.setGravity(Gravity.CENTER);
       rowCampos.addView(codEnt);

       incid.setTextColor(Color.BLACK);
       incid.setText("Inc");
       incid.setGravity(Gravity.CENTER);
       rowCampos.addView(incid);

       sint.setTextColor(Color.BLACK);
       sint.setText("Síntomas");
       sint.setGravity(Gravity.CENTER);
       rowCampos.addView(sint);

       codLoc.setTextColor(Color.BLACK);
       codLoc.setText("Loc");
       codLoc.setGravity(Gravity.CENTER);
       rowCampos.addView(codLoc);

       numMovil.setTextColor(Color.BLACK);
       numMovil.setText("Movil");
       numMovil.setGravity(Gravity.CENTER);
       rowCampos.addView(numMovil);

       sexEdad.setTextColor(Color.BLACK);
       sexEdad.setText("SE");
       sexEdad.setGravity(Gravity.CENTER);
       rowCampos.addView(sexEdad);

       estMovil.setTextColor(Color.BLACK);
       estMovil.setText("EST");
       estMovil.setGravity(Gravity.CENTER);
       rowCampos.addView(estMovil);

       tl.addView(rowCampos);



        //--------------------------------------------------------


    //Paso a tv2 el string que me devuelve el webService, y lo spliteo en un array por el parametro $
    //que me separa al string por incidente
    tv2 = resultado.toString();

    String [] vecDatos = TextUtils.split(tv2, "\\$");


       //voy llenando la tabla con los datos
       for (int i=0; i <=(vecDatos.length)- 1; i++) {

        //Spliteo cada elemento del array que contiene los incidentes, asi obtengo cada campo por separado

        String fila = vecDatos[i].toString(); 
        String [] inc = TextUtils.split(fila, "\\^");

        TableRow tr = new TableRow(this);
        aInt = Integer.parseInt(inc[0]);
        tr.setId(aInt);
        tr.setOnClickListener(this);
        tr.setLayoutParams(new LayoutParams(
                   LayoutParams.WRAP_CONTENT,
                   LayoutParams.WRAP_CONTENT));   


          //------------------------------------------------- 

        //seteo el campo Grado

           TextView grado = new TextView(this);
           grado.setId(200+i);

           int colorInt = Color.parseColor(inc[1]);
           grado.setGravity(Gravity.CENTER);
           grado.setText(inc[2]);

           grado.setBackgroundColor(colorInt);
           grado.setTextColor(Color.BLACK);
           grado.setWidth(10);
           View v = new View(this);
           v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
           v.setBackgroundColor(Color.rgb(0, 0, 0));
           tl.addView(v);
           tr.addView(grado);

         //----------------------------------------------------------------  
         //seteo el campo entidad

           TextView entidad = new TextView(this);
           entidad.setId(300+i);
           entidad.setText(inc[3]);
           entidad.setGravity(Gravity.CENTER);

           entidad.setTextColor(Color.BLACK); 
           tr.addView(entidad);

        //-------------------------------------------------------------------
        //seteo el campo numero de incidente

           TextView numInc = new TextView(this);
           numInc.setId(400+i);
           numInc.setText(inc[4]);
           numInc.setGravity(Gravity.CENTER);
           numInc.setTextColor(Color.BLACK); 
           tr.addView(numInc);

        //-------------------------------------------------------------------  
        //seteo el campo sintomas   
         TextView sintomas = new TextView(this);
           sintomas.setId(500+i);

           //hago funcion para que no me tire error si un sintoma no tiene datos o si
           //tiene menos de 10 caracteres y no lo puedo cortar con el substring de 10 que hago
           if (inc[5].equals(""))
           {

            sintomas.setText("Sin Diag");   

           }

           int toChr = 10;

           if (inc[5].length() < 10) toChr = inc[5].length();

           String strSint = inc[5].substring(0,toChr);
           sintomas.setGravity(Gravity.CENTER);

           sintomas.setText(strSint);




           sintomas.setTextColor(Color.BLACK); 
           tr.addView(sintomas);

           //------------------------------------------------------------------- 

           //seteo el campo localidad
           TextView localidad = new TextView(this);
           localidad.setId(600+i);
           int colorInt2 = Color.parseColor(inc[6]);
           localidad.setText(inc[7]);

           localidad.setBackgroundColor(colorInt2);
           localidad.setGravity(Gravity.CENTER);

           localidad.setTextColor(Color.BLACK); 

           tr.addView(localidad);

           //------------------------------------------------------------------- 

           //seteo el campo movil

           TextView movil = new TextView(this);

           movil.setId(700+i);
           String strMovil = inc[8];

           //hago funcion para que si el campo tiene una A, va en blanco, si tiene una P, en celeste
           String [] vecMovil = TextUtils.split(strMovil, "\\|");
           if (vecMovil[1].equals("A")) {
               movil.setTextColor(Color.BLACK);
               movil.setText(vecMovil[0]);
           }
           else {

               movil.setTextColor(Color.CYAN);
               movil.setText(vecMovil[0]);

           }
           movil.setGravity(Gravity.CENTER);

           tr.addView(movil);
         //------------------------------------------------------------------- 
         //seteo el campo Sexo y Edad (juntos)  
           TextView sexoEdad = new TextView(this);
           sexoEdad.setId(800+i);

           String sexo = inc[9];
           String edad = inc[10].toString();

           String strEdadSexo = sexo.concat(edad);
           sexoEdad.setGravity(Gravity.CENTER);
           sexoEdad.setText(strEdadSexo);

           sexoEdad.setTextColor(Color.BLACK); 

           tr.addView(sexoEdad);
         //-------------------------------------------------------------------    

           TextView est = new TextView(this);
           est.setId(900+i);
           est.setText(inc[11]);
           est.setGravity(Gravity.CENTER);
           est.setTextColor(Color.BLACK); 
           tr.addView(est);


         //-------------------------------------------------------------------   

           TextView domicilio = new TextView(this);
           domicilio.setId(1000+aInt);

           domicilio.setText(inc[12]);





          // tr.addView(domicilio);
           //hago el campo domicilio hidden, esta el textview pero no me ocupa el layout


           // Agrego el tablerow al tablelayout


           //-------------------------------------------------------------------


           TextView latitud = new TextView(this);
           //latitud = (TextView) findViewById(1100+aInt);
           latitud.setId(1100+aInt);

           latitud.setVisibility(View.GONE);
           latitud.setText(inc[13]);


           tr.addView(latitud);

         //-------------------------------------------------------------------


           TextView longitud = new TextView(this);
           longitud.setId(1200+aInt);

           longitud.setVisibility(View.GONE);
           longitud.setText(inc[14]);

          // tr.addView(longitud);

         //-------------------------------------------------------------------

           tl.addView(tr);

I have a tablelayout in my main.xml, but all the other textviews that i add with programatically tablerows are not, cause i am creating them while im having data. I bring data from a webservice, that brings me a string that i split in an array and then i put the arrays information into textviews of each tablerow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:45:28+00:00Added an answer on May 25, 2026 at 7:45 pm

    Use View.INVISIBLE

    longitud.setVisibility(View.INVISIBLE);
    

    This link may also help you out.

    I am not sure but you may also have to set Color to Transparent (I know buttons have this property not sure about textviews.)

    longitub.setBackground(Color.TRANSPARENT);
    //it may be .setBackgroundColor
    

    EDIT:

    To reference in code

    TextView longitub = (TextView) findByViewid(R.id.longitub);
    //For this to work you will have to have the textview with the name longitub
    //in your xml
    

    To declare in XML

    <TextView 
      android:layout_width="fill_parent"           
      //other properties in here
       >
    

    There are also properties in the XML you can use such as

    android:textColor="@android:color/transparent"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make columns in Android ListView? I have this list item layout
I have problem when I try insert some data to Informix TEXT column via
I do not have problem as such but I am quite new to Ruby.
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have a problem using the Java search function in Eclipse on a particular
I have a problem with a little .Net web application which uses the Amazon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.