gpt4 book ai didi

java - Android:在可滑动选项卡布局中切换 Activity

转载 作者:太空宇宙 更新时间:2023-11-03 10:47:45 25 4
gpt4 key购买 nike

在我的 Android 应用程序中有一个可滑动的选项卡布局。它有两个选项卡:New Complain 和 Previous Complains。单击投诉选项卡时,我需要启动 NewComplain.java。这是我的 NewComplain 类代码段:

NewComplain

 public class NewComplain extends SherlockFragmentActivity implements View.OnClickListener {
private int Year;
private int Month;
private int Day;
private static final int DATE_DIALOG_ID = 1;
private View viewLoad;
private TextView heading, date;
private Spinner spiComplain, spiProduct;
private EditText description, contInfo;
private Button btnDate;
private ArrayAdapter<String> complainAdapter, prodAdapter;
private ArrayList<String> lstComplain = new ArrayList<String>();
private ArrayList<String> lstProdNames = new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
viewLoad = LayoutInflater.from(NewComplain.this).inflate(
R.layout.new_complain, null);
setContentView(viewLoad);
}
}

这是我的 TabsPagerAdapter 类。

 package xont.virtusel.v4.controller.sale;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsPagerAdapter extends FragmentPagerAdapter {

public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int index) {

switch (index) {
case 0:

case 1:

}

return null;
}

@Override
public int getCount() {
// get item count - equal to number of tabs
return 2;
}

}

这是我的主要 Activity 类(class)。

 package xont.virtusel.v4.controller.sale;

import xont.virtusel.v4.controller.R;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

public class CustomerComplainActivity extends FragmentActivity implements ActionBar.TabListener {

private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
private String[] tabs = { "New Complain", "Previous Complains" };

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

viewPager.setAdapter(mAdapter);
actionBar.setDisplayHomeAsUpEnabled(true);
//actionBar.setHomeButtonEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
//actionBar.setDisplayShowHomeEnabled(false);
//actionBar.setDisplayShowTitleEnabled(false);

// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}

/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}

@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// on tab selected
// show respected fragment view
viewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}

}

我应该如何将切换 Activity 语句添加到此 TabsPagerAdapter 类中。我用了 Intent 。但它没有用。任何人都可以如此友好地澄清这个问题。提前致谢

最佳答案

你的问题到底是什么?

如果你不能开始新的 Fragment,试试这个:在 TabsPagerAdapterpublic Fragment getItem() 方法中

@Override
public Fragment getItem(int index) {

switch (index) {
case 0:
return new NewComplain();
case 1:
//return some other class
}

return null;
}

并为 NewComplain 类创建一个构造函数

关于java - Android:在可滑动选项卡布局中切换 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19701322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com