user2524
user2524

Reputation: 31

How to create the TableView dynamically as metioned below one screen shot in android

I have to create Table Layout dynamically in android. First one header for one row, second one two column for another row in Table Layout.

https://i.sstatic.net/hKEyk.jpg

Upvotes: 0

Views: 77

Answers (1)

Umesh
Umesh

Reputation: 1609

Ok. So your main concern about to show header with gridview. Simplest way to show as per your requirement is to use Recyclerview with GridLayoutManager.

 RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    GridLayoutManager glm = new GridLayoutManager(this, 2);
    glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            if (position % 4 == 0) {
                return 2;  // row with single column.
            } else {
                return 1;   // row with two column.
            }
        }

        );

        mRecyclerView.setLayoutManager(glm);
        mRecyclerView.setAdapter(mAdapter);

You will get following output.

enter image description here

I hope this will you.

Upvotes: 2

Related Questions