Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created September 20, 2020 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/9582325811226d96eedd70f296181c17 to your computer and use it in GitHub Desktop.
Save codingwithsara/9582325811226d96eedd70f296181c17 to your computer and use it in GitHub Desktop.
【Android Studio Tips】TableLayout – Border & Collapse –
package com.codingwithsara.tabletest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
public class MainActivity extends AppCompatActivity {
private boolean table_flg = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void collapseTable(View view) {
TableLayout table = findViewById(R.id.table);
Button switchBtn = findViewById(R.id.switchBtn);
// setColumnCollapsed(int columnIndex, boolean isCollapsed)
table.setColumnCollapsed(1, table_flg);
table.setColumnCollapsed(2, table_flg);
if (table_flg) {
// Close
table_flg = false;
switchBtn.setText("Show Detail");
} else {
// Open
table_flg = true;
switchBtn.setText("Hide Detail");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment