我有3个带有列表片段('A','B'和'C')的标签,还有导航抽屉列表,其中包含用于过滤3个标签中列表内容的数据列表。我想要的是,当我点击导航抽屉列表中的任何项目时,当前选项卡内容应该刷新,并应在列表中显示新数据。如果我们说我们在选项卡A中并从导航抽屉中选择任何项目,我们如何将字符串发送到选项卡A,以便选项卡列表内容被刷新?
片段活动
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setHomeButtonEnabled(false);
getActionBar().setIcon(R.drawable.clip1);
actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
setTitle("Records");
ActionBar.TabListener tabListener = new ActionBar.TabListener(){
@Override
public void onTabSelected(android.app.ActionBar.Tab tab,
android.app.FragmentTransaction ft) {
// TODO Auto-generated method stub
Tab.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(android.app.ActionBar.Tab tab,
android.app.FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(android.app.ActionBar.Tab tab,
android.app.FragmentTransaction ft) {
// TODO Auto-generated method stub
}};
//Add New Tab
actionBar.addTab(actionBar.newTab().setText("A").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("B").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("C").setTabListener(tabListener));
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
CategoryDatabaseHandler dbcategory = new CategoryDatabaseHandler(this);
categoryList=dbcategory.getCategoryList();
DrawerItemCustomAdapter drawerAdapter = new DrawerItemCustomAdapter(this, categoryList);
mDrawerList.setAdapter(drawerAdapter);
mDrawerList.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position,
long arg3)
{
//actionBar.selectTab(actionBar.getSelectedTab());
}
});
Listfragment
MySimpleArrayAdapter myadapter = new MySimpleArrayAdapter(this.getActivity(),AList);
setListAdapter(myadapter);
ListView listView = getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
答案 0 :(得分:0)
检查this。您可以将LocalBroadcastManager侦听器注册到所需的片段,然后从导航抽屉中选择项目时从MainActivity注册,您将向片段发送消息,以便它可以刷新它的竞争