如何在另一个活动中插入代码手风琴?

时间:2012-11-23 17:32:29

标签: android accordion android-viewpager

我在我的应用程序中使用了一个viewpaer! 我需要在其中一个屏幕上插入手风琴视图!

我找到了使用手风琴所需的代码,但不知道如何在我的Activity.java中输入代码!

对于我使用viewpager的模型很复杂。

我想知道如何在我的Activity中输入手风琴代码。

这里是我的DiferencialActivity.java的代码:

package com.example.resina.e.marcon;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class DiferencialActivity extends Fragment {

    Button button1,button2;
    LinearLayout panel1,panel2;

    public static Fragment newInstance(Context context) {
        DiferencialActivity f = new DiferencialActivity();

        return f;


    }

    @Override
    public View onCreateView(LayoutInflater inflater, 
            ViewGroup container,Bundle savedInstanceState) {
        ViewGroup root = (ViewGroup) inflater.inflate(R.layout.diferencial_layout, null);

        return root;



    }



}

这是您需要输入我的DiferencialActivity的代码,因此她可以解释为此活动定义的按钮的布局:

package com.example.resina.e.marcon;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class teste extends Activity
{
      Button button1,button2;
      LinearLayout panel1,panel2;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.diferencial_layout);

        button1 = (Button)findViewById(R.id.button1);
        button2 = (Button)findViewById(R.id.button2);

        button1.setOnClickListener(buttonClickListener);
        button2.setOnClickListener(buttonClickListener);


        panel1 = (LinearLayout)findViewById(R.id.panel1);
        panel2 = (LinearLayout)findViewById(R.id.panel2);

        /*We make both the panels, by default, invisible to user
        and make them appear on button click event in follwing manner*/

        panel1.setVisibility(View.GONE);
        panel2.setVisibility(View.GONE);



    }


    public OnClickListener buttonClickListener = new OnClickListener()
    {

            @Override
            public void onClick(View v)
            {
                  Button ClickedButton = (Button)v;

                  if(ClickedButton.getId()== button1.getId())
                  {
                            panel1.setVisibility(View.VISIBLE);
                          panel2.setVisibility(View.GONE);
                  }
                  else if(ClickedButton.getId()== button2.getId())
                  {
                        panel1.setVisibility(View.GONE);
                    panel2.setVisibility(View.VISIBLE);
                  }
            }
      };


}

如何在DiferencialActivity.java中插入此代码?

0 个答案:

没有答案