0
탭이있는 ActionBar를 표시하는 Eclipse의 FragmentActivity를 작성했습니다. 첫 번째 탭에서는 목록이있는 조각을 표시하고 다음 탭에는 텍스트가있는 조각을 표시합니다. 그런 다음 첫 번째 탭의 항목 하나를 선택했을 때 두 번째 조각을 다른 목록 조각으로 변경하십시오. 여기에 내 코드 : ListaFragment에서뷰 페이지 탭에서 조각을 업데이트하는 방법은 무엇입니까?
public class TabActivity extends FragmentActivity implements ActionBar.TabListener {
static final int NUM_TABS = MyTab.values().length;
public enum MyTab{
Categorias(0), Productos(1);
private final int index;
MyTab(int i) {
this.index = i;
}
}
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pedido);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.pedido, menu);
return true;
}
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(position);
}
@Override
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
private FragmentManager mFragmentManager;
private TextoFragment mTextoFragment;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
mFragmentManager = fm;
}
@Override
public Fragment getItem(int position) {
return TabFragment.nuevoFragment(position);
}
@Override
public int getCount() {
return NUM_TABS;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (MyTab.values()[position]) {
case Categorias:
return getString(R.string.title_categorias).toUpperCase(l);
case Productos:
return getString(R.string.title_productos).toUpperCase(l);
}
return "";
}
}
/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class TabFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
static Fragment nuevoFragment(int position) {
Fragment f;
Bundle args = new Bundle();
switch (Pestaña.values()[position]) {
case Categorias:
f = new ListaFragment();
args.putInt("tipoObjeto", TipoObjeto.Categoria.ordinal());
break;
case Productos:
if (EstadoHT.categoriaActual == null) {
f = new TextoFragment();
args.putString(TextoFragment.ARG_MENSAJE,
"Elija primero una categoría");
} else {
f = new ListaFragment();
args.putInt(ListaFragment.ARG_TIPO_OBJETO,
TipoObjeto.Producto.ordinal());
}
break;
default:
f = new TabFragment();
args = new Bundle();
args.putInt(TabFragment.ARG_SECTION_NUMBER, position);
}
f.setArguments(args);
return f;
}
private View lanzarEstadoPedido(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab_estado_pedido,
container, false); // Muestra el layout
TextView lblMesa = (TextView) rootView.findViewById(R.id.lblMesa);
lblMesa.setText("Nada");
return rootView;
}
public TabFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int valorPestaña = getArguments().getInt(ARG_SECTION_NUMBER, 0);
switch (MyTab.values()[valorPestaña]) {
case Pedido:
return lanzarEstadoPedido(inflater, container,
savedInstanceState);
default:
return null;
}
}
}
}
: 이클립스와 나에 의해
TabActivity를 만들어
가능 난 .. 두 번째 탭의 조각을 업로드 할 ListaFragment에서 다음public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Intent dato = new Intent();
IObjetoHT o = (IObjetoHT) lvlista.getItemAtPosition(position);
switch (tipo) {
case Categoria:
App.categoriaActual = (Categoria) o;
TabActivity actPedido = (TabActivity) getActivity();
ActionBar actionBar = actPedido.getActionBar();
actPedido.mViewPager.setCurrentItem(TabActivity.MyTab.Productos.ordinal());
break;
case Producto:
break;
default:
dato.putExtra(ARG_OBJETO_A_DEVOLVER, o);
act.setResult(act.RESULT_OK, dato);
act.finish();
}
입니까?
체크 아웃 http://stackoverflow.com/questions/7723964/replace-fragment-inside-a-viewpager – Catherine
@ 캐서린 나는 체크했다. 그러나 그것은 나에게 도움이되지 않는다. 당신의 링크에? – Millas
특정 조건에서 뷰 페이지의 단편을 바꾸려고한다고 생각 했습니까? – Catherine