开发者

Populating data on gridview

开发者 https://www.devze.com 2023-01-15 20:43 出处:网络
In my android app, i have a particular scenario, for one of the screens. I require 2 button,one on each side of the corner(left and right).

In my android app, i have a particular scenario, for one of the screens.

I require 2 button,one on each side of the corner(left and right). Below this i want to populate data in a control.

If开发者_如何学C left button is clicked, the control should be a gridview. If right button is clicked , the control should be a listview.

And accordingly the data should be populated.

How should i approach this scenario. Should i create controls dynamically, or use xml instead

Rgds


Create the view with two different layouts.

Assume that you have 2 xml layouts named gridLayout.xml and listLayout.xml and that somehow mode is determined earlier in your code and set to one of two constants GRIDVIEW or LISTVIEW. Than you can use a code fragment like:

  private Context        m_Context = activity.getBaseContext();
  private ViewHolder     m_Inflater = LayoutInflater.from(m_Context);

...

  if (mode == GRIDTYPE)
    viewDisplay = m_Inflater.inflate(R.layout.gridLayout, null);
  } else {
    viewDisplay = m_Inflater.inflate(R.layout.listLayout, null);
0

精彩评论

暂无评论...
验证码 换一张
取 消