2

Hey guys I trying to create a app having a linear layout.and linear layout may have more than one Grid View and it would be generate dynamically.I am trying to do this but it is adding only one grid View not more than one. Any one have answer for this?

private GridView gv[];
    .
    .
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    ....
    gv = new GridView[2];
    ....
    .....
    protected void onPostExecute(Boolean result) {
            if (al1.length == 2)
                linearLayout.setWeightSum(2.0f);
            for (int i = 0; i < al1.length; i++) {
                gv[i] = new GridView(getApplicationContext());
                if (al1.length == 2) {
                    gv[i].setNumColumns(1);
                } else
                {
                    gv[i].setNumColumns(2);
                }
                gv[i].setAdapter(new gridadapter(getApplicationContext(),
                        al1[i]));
                linearLayout.addView(gv[i]);

1 Answer 1

2

Take a listview and take a linear layout with horizontal oreintation as its item...then add your items to this linear layout...it will work as per your requirement and will make things work easier and faster..

Tell me if you want more explanation...

Sign up to request clarification or add additional context in comments.

3 Comments

Actually I know that list will work efficiently but I need to implement Grid View and it is working also but in case of single Grid View adding when trying to add 2 grid View it is showing only one if you have any solution for this please help me.
add everything in a scrollview...there may be a problem with space...also specify height and width of every gridvew you are adding or else it will take complete space...
no it is not working now I am trying to solve this by list and thanks for giving me solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.