简体   繁体   中英

Android how to hide the table lyout

In my android application a love compatibility test is doing.. where first the details of boys and then details of girls are entered in the same page..one after another. and separate save button for saving boy details and girl details and these data is saved in separate databases. and there is a recall button also there for both boys and girls. When this recall button is pressed the database will opened and from that user can select the name to be checked. When he press the corresponding data has to be entered into the corresponding edittexts. In my case I don't know how to close this tablerow. that mean the database opened.then only the data will go to the corresponding edittext box.

I am giving my code below

MainActivity

btn4.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Cursor c = dbb.rawQuery("SELECT * from Data3", null);
            int count = c.getCount();
            c.moveToFirst();




            TableLayout tableLayout = new TableLayout(getApplicationContext());
            tableLayout.setVerticalScrollBarEnabled(true);
            TableRow tableRow;
            TextView textView1, textView2,textView3, textView4, textView5, textView6, textView7, textView8 ;
            tableRow = new TableRow(getApplicationContext());         
            textView1 = new TextView(getApplicationContext());
            textView1.setText("First Name");
            textView1.setTextColor(Color.BLACK);
            textView1.setTypeface(null, Typeface.BOLD);
            textView1.setPadding(20, 20, 20, 20);
            tableRow.addView(textView1);

            textView2 = new TextView(getApplicationContext());
            textView2.setText("Last Name");
            textView2.setTextColor(Color.RED);
            textView2.setTypeface(null, Typeface.BOLD);
            textView2.setPadding(10, 10, 10, 10);
            tableRow.addView(textView2);

            tableLayout.addView(tableRow);


            for(Integer j=0; j<count; j++)              
            {

                tableRow = new TableRow(getApplicationContext());

                textView3= new TextView(getApplicationContext());
                textView3.setText(c.getString(c.getColumnIndex("ffirstname")));
                textView3.setClickable(true);
                ett1=textView3.getText().toString();

                textView4 = new TextView(getApplicationContext());
                textView4.setText(c.getString(c.getColumnIndex("fmiddlename")));
                textView4.setClickable(true);
                ett2=textView4.getText().toString();


                textView5 = new TextView(getApplicationContext());
                textView5.setText(c.getString(c.getColumnIndex("flastname")));
                textView5.setClickable(true);
                ett3=textView5.getText().toString();


                textView6 = new TextView(getApplicationContext());
                textView6.setText(c.getString(c.getColumnIndex("fdayofbirth")));
                textView6.setClickable(true);
                ett4=textView6.getText().toString();


                textView7 = new TextView(getApplicationContext());
                textView7.setText(c.getString(c.getColumnIndex("fmonthofbirth")));
                textView7.setClickable(true);
                ett5=textView7.getText().toString();

                textView8 = new TextView(getApplicationContext());
                textView8.setText(c.getString(c.getColumnIndex("fyearofbirth")));
                textView8.setClickable(true);
                ett6=textView8.getText().toString();


                textView3.setPadding(10, 10, 10,10);
                textView5.setPadding(10, 10, 10, 10);
                tableRow.addView(textView3);
                tableRow.addView(textView5);
                tableLayout.addView(tableRow);
                c.moveToNext();

                final List<String> list = new ArrayList<String>();
                list.add(textView3.getText().toString());
                list.add(textView4.getText().toString());
                list.add(textView5.getText().toString());         
                list.add(textView6.getText().toString());
                list.add(textView7.getText().toString());         
                list.add(textView8.getText().toString());


                textView3.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {                           
                        // TODO Auto-generated method stub


                    }
                });



            }

            c.close();
            setContentView(tableLayout);
              dbb.close();

        }
    });

Declare the table layout out side button click and to make it GONE/INVISIBLE do Like this

 tablelayout.setVisibility(View.INVISIBLE);//white space will be available

Or

 tablelayout.setVisibility(View.GONE);//No white space

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM