操作栏 +选项卡导航(MapView + ListView)片段

发布于 2024-12-25 18:45:17 字数 2448 浏览 0 评论 0原文

我想知道如何使用列表片段,同时使用列表顶部有 4 个过滤器按钮的静态线性布局。问题是:

首先,我使用 ActionBarSherlock 中的操作栏 + 选项卡导航:

QuestList 扩展 FragmentMapActivity实现 ActionBar.TabListener

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getTabs();
}

private void getTabs() {
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab tab1 = getSupportActionBar().newTab();
    tab1.setText("Geo");
    tab1.setTabListener(this);
    getSupportActionBar().addTab(tab1);

    ActionBar.Tab tab2 = getSupportActionBar().newTab();
    tab2.setText("No Geo");
    tab2.setTabListener(this);
    getSupportActionBar().addTab(tab2);
}

...

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    if (tab.getText().toString().compareTo("Geo") == 0) {
        getSupportFragmentManager().beginTransaction().replace(android.R.id.content, Map.getInstance()).commit();
    }
    else {
        getSupportFragmentManager().beginTransaction().replace(android.R.id.content, List.newInstance(0)).commit();     
    }
}

我在 MapView 中遇到了一些问题,但我最终修复了所有问题。现在的问题是我想要这样的东西:

Static LinearLayout + ListFragment

List 扩展 ListFragment

...
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    initializations();

    getQuests();

    if (gigHash.isEmpty()) {
        TextView eList = new TextView(getActivity());
        eList.setText(R.string.no_loc_gig_no_items);
        eList.setWidth(Gravity.CENTER);
    }
    else {
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mAdapter = new NoLocGigAdapter(getActivity(),R.layout.gig_noloc_row_land,gigList);
        }
        else {
            mAdapter = new NoLocGigAdapter(getActivity(),R.layout.gig_noloc_row,gigList);
        }                       
        setListAdapter(mAdapter);
    }
}
...

所以我使用自己的适配器,并从服务获取所有项目。

问题是,在进行事务时,我只能使用一个片段,并且我必须使用自己的 ArrayAdapter 动态地显示项目,所以我不知道如何将一部分静态代码包含到该视图中...

任何建议?我觉得用碎片处理有点奇怪!

PS:一开始,我以为我可以调用一个fragment,这样,在线性布局中调用一个静态xml,在里面调用一个ListFragment,但我想我不能这样做,对吧?

I'm wondering how can I work with a listfragment, and at the same time, using an static linearlayout with 4 filter buttons at the top of the list. Here is the problem:

First of all, I use an Action Bar + Tab Navigation from ActionBarSherlock :

QuestList extends FragmentMapActivity implements ActionBar.TabListener

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getTabs();
}

private void getTabs() {
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab tab1 = getSupportActionBar().newTab();
    tab1.setText("Geo");
    tab1.setTabListener(this);
    getSupportActionBar().addTab(tab1);

    ActionBar.Tab tab2 = getSupportActionBar().newTab();
    tab2.setText("No Geo");
    tab2.setTabListener(this);
    getSupportActionBar().addTab(tab2);
}

...

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    if (tab.getText().toString().compareTo("Geo") == 0) {
        getSupportFragmentManager().beginTransaction().replace(android.R.id.content, Map.getInstance()).commit();
    }
    else {
        getSupportFragmentManager().beginTransaction().replace(android.R.id.content, List.newInstance(0)).commit();     
    }
}

I got some problems with the MapView, but I finally fixed all of them. Now the problem is that I want something like this:

Static LinearLayout + ListFragment

List extends ListFragment

...
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    initializations();

    getQuests();

    if (gigHash.isEmpty()) {
        TextView eList = new TextView(getActivity());
        eList.setText(R.string.no_loc_gig_no_items);
        eList.setWidth(Gravity.CENTER);
    }
    else {
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mAdapter = new NoLocGigAdapter(getActivity(),R.layout.gig_noloc_row_land,gigList);
        }
        else {
            mAdapter = new NoLocGigAdapter(getActivity(),R.layout.gig_noloc_row,gigList);
        }                       
        setListAdapter(mAdapter);
    }
}
...

So I'm using my own adapter and I get all my items from a service.

The problem is, doing the transaction, I can only use a fragment, and I have to show the items dinamically with my own ArrayAdapter, so I don't know how to include a part of static code into that view...

Any suggestion? I think that handle with fragments it's a little weird!

PS: At first, I thought that I could call a fragment, and this, calling a static xml within the linearlayout and a ListFragment inside, but I think I can't do this, right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文