1

アクティビティでボトムタブを使用したいのですが、古いアクティビティ自体に何らかの機能があり、タブに別のアクティビティを使用せずに、アクティビティ自体でタブ機能を使用できますか?このように試しました。

public class GinfyActivity extends Activity {


    /** Called when the activity is first created. */

    public GridviewAdapter mAdapter;
    private Spinner spinner1;
    public String selectprayer;


    ArrayList<GridviewAdapter> results = new ArrayList<GridviewAdapter>();

    private ArrayList<String> listginfy;
    private ArrayList<Integer> listimage;

    private GridView gridView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_ginfy);

        TabHost mTabHost = (TabHost)findViewById(android.R.id.tabhost);

        mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(new Intent(GinfyActivity.this,Audioprayer.class)));
        mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(new Intent(GinfyActivity.this,TTSMeditation.class)));
        mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(new Intent(GinfyActivity.this,TTSList.class)));

        mTabHost.setCurrentTab(0);

        addListenerOnButton();
        addListenerOnSpinnerItemSelection();






        prepareList();


        // prepared arraylist and passed it to the Adapter class
   mAdapter = new GridviewAdapter(this,listginfy, listimage);

        // Set custom adapter to gridview
        gridView = (GridView) findViewById(R.id.gridView1);
        gridView.setAdapter(mAdapter);

        // Implement On Item click listener
        gridView.setOnItemClickListener(new OnItemClickListener() 
        {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {


                if (selectprayer.equals("www.ginfy.com"))
                {

                switch(position)
                { 
                case 0:
                Intent newActivity = new Intent(GinfyActivity.this,MainActivity.class);
                startActivity(newActivity);
                break;

                case 2:
                Intent new1Activity = new Intent(GinfyActivity.this,AndroidTabLayoutActivity.class);
                startActivity(new1Activity);
                break;
                default:
                    Toast.makeText(GinfyActivity.this, "Coming Soon", Toast.LENGTH_LONG).show();
                    }
                }
                else
                {

                    switch(position)
                    {
                    case 0:
                    Intent new2Activity = new Intent(GinfyActivity.this,YourPrayerActivity.class);
                    startActivity(new2Activity);
                    break;

                    case 1:
                    Intent new3Activity = new Intent(GinfyActivity.this,AndroidTabLayoutActivity1.class);
                    startActivity(new3Activity);
                    break;

                    case 3:
                    Intent new4Activity = new Intent(GinfyActivity.this,ExperiencesActivity.class);
                    startActivity(new4Activity);
                    break;
                    default:
                        Toast.makeText(GinfyActivity.this, "Coming Soon", Toast.LENGTH_LONG).show();
                        }


                }
            }
        });
    }




    public void addListenerOnSpinnerItemSelection() {
        {
            spinner1 = (Spinner) findViewById(R.id.spinner1);
            spinner1.setOnItemSelectedListener(new OnItemSelectedListener() 
            {
                public void onItemSelected(AdapterView<?> parent, View view, int position,
                        long id) {

                    spinner1.setSelection(position);
                    //spinnerCapital.setSelection(position);

                    selectprayer = (String) spinner1.getSelectedItem();

                    //Toast.makeText(getBaseContext(), selectprayer, Toast.LENGTH_SHORT).show();
                    //String myStatesCapital = (String) spinnerCapital.getSelectedItem();



                    //tvCapital.setText("My State is " + myState + ".And its Capital is "
                            //+ myStatesCapital);

                }

                public void onNothingSelected(AdapterView<?> parent) {

                }});
        }
        }




    public void addListenerOnButton() {
        spinner1 = (Spinner) findViewById(R.id.spinner1);

    }

    public void prepareList()
    {
        listginfy = new ArrayList<String>();

        listginfy.add("Prayers");
        listginfy.add("Prayer room");
        listginfy.add("God gallery");
        listginfy.add("Experiences");


        listimage = new ArrayList<Integer>();
        listimage.add(R.drawable.ginfyprayer);
        listimage.add(R.drawable.poojaroom1);
        listimage.add(R.drawable.godsgallery);
        listimage.add(R.drawable.temp1);

    }


}

mylayout でもタブ機能を宣言しましたが、アクティビティが開かず、アクティビティが停止したと表示されます

いくつかのlogcatエラーが表示されています。

09-12 08:43:45.615: E/AndroidRuntime(2630): FATAL EXCEPTION: main
09-12 08:43:45.615: E/AndroidRuntime(2630): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jsonandroid/com.example.jsonandroid.GinfyActivity}: java.lang.NullPointerException
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.os.Looper.loop(Looper.java:137)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.ActivityThread.main(ActivityThread.java:5039)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at java.lang.reflect.Method.invokeNative(Native Method)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at java.lang.reflect.Method.invoke(Method.java:511)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at dalvik.system.NativeStart.main(Native Method)
09-12 08:43:45.615: E/AndroidRuntime(2630): Caused by: java.lang.NullPointerException
09-12 08:43:45.615: E/AndroidRuntime(2630):     at com.example.jsonandroid.GinfyActivity.onCreate(GinfyActivity.java:44)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.Activity.performCreate(Activity.java:5104)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-12 08:43:45.615: E/AndroidRuntime(2630):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-12 08:43:45.615: E/AndroidRuntime(2630):     ... 11 more
4

2 に答える 2