Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从选项卡获取adpter在片段中的位置_Java_Android_Android Fragments - Fatal编程技术网

Java 从选项卡获取adpter在片段中的位置

Java 从选项卡获取adpter在片段中的位置,java,android,android-fragments,Java,Android,Android Fragments,我在位置0有一个静态选项卡,它从服务器返回数据。我想通过位置返回数据从服务器在该位置1,2,3等。我会张贴代码,我不能找出这是错误的代码 xml片段 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_heig

我在位置0有一个静态选项卡,它从服务器返回数据。我想通过位置返回数据从服务器在该位置1,2,3等。我会张贴代码,我不能找出这是错误的代码

xml片段

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context="app.amplitudenet.com.materialapp.Fragmentos.AtendimentoHistorico">
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/IDProcolo1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Numero do Protocolo"
        android:layout_marginLeft="12dp"
        android:textSize="24dp"
        android:layout_marginTop="12dp"
        android:textColor="@color/colorPrimary"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Histórico: "
        android:id="@+id/textoHistorico"
        android:textStyle="bold"
        android:layout_below="@+id/IDProcolo1"
        android:layout_alignBottom="@+id/Historico"
        android:layout_alignLeft="@+id/IDProcolo1"
        android:layout_alignStart="@+id/IDProcolo1" />

    <TextView
        android:id="@+id/Historico"
        android:text="Número do Histórico"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#666"
        android:layout_below="@+id/IDProcolo1"
        android:layout_toRightOf="@+id/textoHistorico"
        android:layout_toEndOf="@+id/textoHistorico" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Responsável: "
        android:layout_marginTop="5dp"
        android:id="@+id/textoDataCadastro"
        android:textStyle="bold"
        android:layout_below="@+id/Historico"
        android:layout_marginLeft="12dp"
        android:layout_marginStart="8dp"
        />

    <TextView
        android:id="@+id/FuncionarioHistorico"
        android:text="Thiago Belão"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#666"
        android:layout_alignTop="@+id/textoDataCadastro"
        android:layout_toRightOf="@+id/textoDataCadastro"
        android:layout_toEndOf="@+id/textoDataCadastro" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Data de Solução: "
        android:layout_marginTop="5dp"
        android:id="@+id/textoDataSolucaoHistorico"
        android:textStyle="bold"
        android:layout_below="@+id/textoDataCadastro"
        android:layout_marginLeft="12dp"
        android:layout_marginStart="8dp"
        />

    <TextView
        android:id="@+id/DataSolucaoHistorico"
        android:text="19/11/2015"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#666"
        android:layout_alignTop="@+id/textoDataSolucaoHistorico"
        android:layout_toRightOf="@+id/textoDataSolucaoHistorico"
        android:layout_toEndOf="@+id/textoDataSolucaoHistorico" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Etapa Finalizada : "
        android:layout_marginTop="5dp"
        android:id="@+id/textoEtapa"
        android:textStyle="bold"
        android:layout_below="@+id/textoDataSolucaoHistorico"
        android:layout_marginLeft="12dp"
        android:layout_marginStart="8dp"
        />

    <TextView
        android:id="@+id/Etapa"
        android:text="Sim / Não"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#666"
        android:layout_alignTop="@+id/textoEtapa"
        android:layout_toRightOf="@+id/textoEtapa"
        android:layout_toEndOf="@+id/textoEtapa" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Solicitação: "
        android:layout_marginTop="5dp"
        android:layout_marginLeft="12dp"
        android:id="@+id/textoSolicitacaoHistorico"
        android:layout_below="@+id/textoEtapa"
        android:textStyle="bold"
        />

    <TextView
        android:id="@+id/textoHistoricoAtendimento"
        android:text="Texto da Solicitação"
        android:layout_width="fill_parent"
        android:layout_marginTop="8dp"
        android:layout_height="fill_parent"
        android:textColor="#666"
        android:textSize="14dp"
        android:layout_marginLeft="12dp"
        android:layout_below="@+id/textoSolicitacaoHistorico"
        />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/IntPosicao"
        android:text="1"
        android:visibility="gone" />


</RelativeLayout>
}

adpter代码

public class AtendimentoTabsAdpter extends FragmentStatePagerAdapter {
ArrayList<String> Titles; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created
SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();


// Build a Constructor and assign the passed Values to appropriate values in the class
public AtendimentoTabsAdpter(FragmentManager fm,ArrayList<String> mTitles, int mNumbOfTabsumb) {
    super(fm);

    this.Titles = mTitles;
    this.NumbOfTabs = mNumbOfTabsumb;

}

//This method return the fragment for the every position in the View Pager
@Override
public Fragment getItem(int position) {

    if(position == 0) // if the position is 0 we are returning the First tab
    {
        AtendimentoDetalhado tab1 = new AtendimentoDetalhado();
        return tab1;
    }

     else          // As we are having 2 tabs if the position is now 0 it must be 1 so we are returning second tab
    {
        AtendimentoHistorico tab2 = new AtendimentoHistorico();
        return tab2;
    }



}

// This method return the titles for the Tabs in the Tab Strip

@Override
public CharSequence getPageTitle(int position) {

    return Titles.get(position);
}

// This method return the Number of tabs for the tabs Strip

@Override
public int getCount() {
    return NumbOfTabs;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    Fragment fragment = (Fragment) super.instantiateItem(container, position);
    registeredFragments.put(position, fragment);
    return fragment;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    registeredFragments.remove(position);
    super.destroyItem(container, position, object);
}

public Fragment getRegisteredFragment(int position) {
    return registeredFragments.get(position);
}
公共类ATendmentOtaBSadpter扩展了FragmentStatePagerAdapter{
ArrayList Titles;//这将存储创建ViewPagerAdapter时要传递的选项卡的标题
int NumbOfTabs;//存储选项卡的数量,创建ViewPagerAdapter时也会传递该数量
SparseArray registeredFragments=新SparseArray();
//构建构造函数并将传递的值分配给类中的适当值
公共ATeIndicationOTABSADPTER(FragmentManager格式、ArrayList mTitles、int mNumbOfTabsumb){
超级(fm);
这个.Titles=mTitles;
this.NumbOfTabs=mNumbOfTabsumb;
}
//此方法返回视图寻呼机中每个位置的片段
@凌驾
公共片段getItem(int位置){
if(position==0)//如果位置为0,则返回第一个选项卡
{
AtendimentoDetalhado tab1=新的AtendimentoDetalhado();
返回表1;
}
else//由于我们有两个制表符,如果位置现在为0,则必须为1,因此我们返回第二个制表符
{
AtendimentoHistorico tab2=新的AtendimentoHistorico();
返回表2;
}
}
//此方法返回选项卡条中选项卡的标题
@凌驾
公共字符序列getPageTitle(int位置){
返回标题。获取(位置);
}
//此方法返回选项卡条的选项卡数
@凌驾
public int getCount(){
回程制动;
}
@凌驾
公共对象实例化项(视图组容器,int位置){
Fragment Fragment=(Fragment)super.instanceItem(容器,位置);
注册碎片。放置(位置,碎片);
返回片段;
}
@凌驾
公共项(视图组容器、int位置、对象){
注册碎片。移除(位置);
超级项目(容器、位置、对象);
}
公共片段getRegisteredFragment(int位置){
返回registeredFragments.get(位置);
}

我已经更改了adpater并创建了一个列表,更新了rest api中的方法现在我有两个选项卡和所有需要的数据

我已经更改了adpater并创建了一个列表,更新了rest api中的方法现在我有两个选项卡和所有需要的数据

public class AtendimentoHistorico extends Fragment {
Historico item;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View tela =  inflater.inflate(R.layout.fragment_atendimento_historico, container, false);
    Bundle id = getActivity().getIntent().getExtras();
    String codigo =  id.getString("codigo");
    int codid = Integer.parseInt(codigo);
    TextView posicao = (TextView) tela.findViewById(R.id.IntPosicao);
    String coisocoisado = posicao.getText().toString();
    int pos;
    pos = Integer.parseInt(coisocoisado);
    item =  new Historico(codid,pos);
    Autenticado(item);
    return tela;
}
public void Autenticado(Historico historico) {
    ServerRequests server = new ServerRequests(getActivity());
    server.getDadosHistoricoBackground(historico, new GetHistoricoCallBack() {
        @Override
        public void done(Historico returnedHistorico) {
            if (returnedHistorico == null)
            {
                Erro();
            }
            else
            {
                Bundle id = getActivity().getIntent().getExtras();
                String get = id.getString("id");
                TextView momo = (TextView) getActivity().findViewById(R.id.IDProcolo1);
                momo.setText("Protocolo Nº "+get);
                TextView momo1 = (TextView) getActivity().findViewById(R.id.FuncionarioHistorico);
                if (returnedHistorico.Setor == "null")
                {
                    momo1.setText(""+returnedHistorico.Funcionario);
                }
                else
                {
                    momo1.setText(""+returnedHistorico.Setor);
                }
                TextView momo2 = (TextView) getActivity().findViewById(R.id.DataSolucaoHistorico);
                momo2.setText(""+returnedHistorico.Data);
                TextView momo3 = (TextView) getActivity().findViewById(R.id.Etapa);
                momo3.setText(""+returnedHistorico.Etapa);
                TextView momo4 = (TextView) getActivity().findViewById(R.id.textoHistoricoAtendimento);
                momo4.setText(""+returnedHistorico.Solucao);
                TextView momo5 = (TextView) getActivity().findViewById(R.id.Historico);
                momo5.setText(""+returnedHistorico.Sequencia);
                TextView momo6 = (TextView) getActivity().findViewById(R.id.txtFinalizado);
                momo6.setText(""+returnedHistorico.Finalizado);
            }

        }
    });
}


private void Erro() {
    AlertDialog.Builder alerta = new AlertDialog.Builder(getActivity());
    alerta.setMessage("Erro ao Carregar Histórico de Atendimento");
    alerta.setPositiveButton("OK", null);
    alerta.show();
}
public class AtendimentoTabsAdpter extends FragmentStatePagerAdapter {
ArrayList<String> Titles; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created
SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();


// Build a Constructor and assign the passed Values to appropriate values in the class
public AtendimentoTabsAdpter(FragmentManager fm,ArrayList<String> mTitles, int mNumbOfTabsumb) {
    super(fm);

    this.Titles = mTitles;
    this.NumbOfTabs = mNumbOfTabsumb;

}

//This method return the fragment for the every position in the View Pager
@Override
public Fragment getItem(int position) {

    if(position == 0) // if the position is 0 we are returning the First tab
    {
        AtendimentoDetalhado tab1 = new AtendimentoDetalhado();
        return tab1;
    }

     else          // As we are having 2 tabs if the position is now 0 it must be 1 so we are returning second tab
    {
        AtendimentoHistorico tab2 = new AtendimentoHistorico();
        return tab2;
    }



}

// This method return the titles for the Tabs in the Tab Strip

@Override
public CharSequence getPageTitle(int position) {

    return Titles.get(position);
}

// This method return the Number of tabs for the tabs Strip

@Override
public int getCount() {
    return NumbOfTabs;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    Fragment fragment = (Fragment) super.instantiateItem(container, position);
    registeredFragments.put(position, fragment);
    return fragment;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    registeredFragments.remove(position);
    super.destroyItem(container, position, object);
}

public Fragment getRegisteredFragment(int position) {
    return registeredFragments.get(position);
}