0

I'm having some trouble with implementing Activity Groups into my code.

I have a 4 Radio Buttons at the bottom of my screen enter image description here.

Once one of them gets clicked, I would like the activity window to change, but the MainActivity to stay there so the Action Bar and Radio Buttons will stay.

So in a simpler form it would be like starting Activity B, C, D, and E in Activity A.

I have come across a solution to but don't know how I am going to be able to implement it into my code as I already have everything set up.

Possible solution: http://ericharlow.blogspot.co.uk/2010/09/experience-multiple-android-activities.html

Any help would be highly appreciated!

Here's my Main Activity:

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.GridView;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends Activity {

GridView list;
LazyAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    list = (GridView) findViewById(R.id.list);
    adapter = new LazyAdapter(this, mStrings);
    list.setAdapter(adapter);

    RadioButton btnAll = (RadioButton) findViewById(R.id.btnAll);
    btnAll.setOnCheckedChangeListener(btnAllOnCheckedChangeListener);

    RadioButton btnCategories = (RadioButton) findViewById(R.id.btnCategories);
    btnCategories
            .setOnCheckedChangeListener(btnCategoriesOnCheckedChangeListener);

    RadioButton btnPopular = (RadioButton) findViewById(R.id.btnPopular);
    btnPopular
            .setOnCheckedChangeListener(btnPopularOnCheckedChangeListener);

    RadioButton btnAbout = (RadioButton) findViewById(R.id.btnAbout);
    btnAbout.setOnCheckedChangeListener(btnAboutOnCheckedChangeListener);
}

private CompoundButton.OnCheckedChangeListener btnAllOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        if (isChecked) {

            Toast.makeText(getApplicationContext(), "Opened ALL tab",
                    Toast.LENGTH_SHORT).show();
        }
    }

};

private CompoundButton.OnCheckedChangeListener btnCategoriesOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        if (isChecked) {

            Toast.makeText(getApplicationContext(),
                    "Opened CATEGORIES tab", Toast.LENGTH_SHORT).show();

        }
    }

};

private CompoundButton.OnCheckedChangeListener btnPopularOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        if (isChecked) {
            Toast.makeText(getApplicationContext(), "Opened POPULAR tab",
                    Toast.LENGTH_SHORT).show();
        }
    }

};

private CompoundButton.OnCheckedChangeListener btnAboutOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        if (isChecked) {
            Toast.makeText(getApplicationContext(), "Opened ABOUT tab",
                    Toast.LENGTH_SHORT).show();
        }
    }

};

@Override
public void onDestroy() {
    list.setAdapter(null);
    super.onDestroy();
}

private String[] mStrings = {
        "www.LOTSOFURLSHERE.com" };

};

Main Activity XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background" >

<GridView
    android:id="@+id/list"
    style="@style/PhotoGridLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnWidth="@dimen/image_thumbnail_size"
    android:horizontalSpacing="@dimen/image_thumbnail_spacing"
    android:numColumns="2"
    android:stretchMode="columnWidth"
    android:verticalSpacing="@dimen/image_thumbnail_spacing" >
</GridView>

<RadioGroup
    android:id="@+id/radiogroup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/navbar_background"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/btnAll"
        style="@style/navbar_button"
        android:drawableTop="@drawable/navbar_allselector"
        android:text="@string/allwallpapers"
        android:textColor="#FFFFFF"
         />

    <RadioButton
        android:id="@+id/btnCategories"
        style="@style/navbar_button"
        android:layout_marginLeft="5dp"
        android:drawableTop="@drawable/navbar_pictureselector"
        android:text="@string/categories"
        android:textColor="#FFFFFF"
         />

    <RadioButton
        android:id="@+id/btnPopular"
        style="@style/navbar_button"
        android:layout_marginLeft="5dp"
        android:drawableTop="@drawable/navbar_videoselector"
        android:text="@string/popular"
        android:textColor="#FFFFFF" />

    <RadioButton
        android:id="@+id/btnAbout"
        style="@style/navbar_button"
        android:layout_marginLeft="5dp"
        android:drawableTop="@drawable/navbar_fileselector"
        android:text="@string/about"
        android:textColor="#FFFFFF" />
</RadioGroup>

</RelativeLayout>
Jack
  • 2,043
  • 7
  • 40
  • 69
  • 1
    Use fragments for loading different screens... Make A,B,C,D,E activities as fragments & add to main activity... this link will help you.. http://www.javacodegeeks.com/2013/06/fragment-in-android-tutorial-with-example-using-webview.html – Anil kumar Sep 19 '13 at 13:15
  • @Anilkumar Also, When using Fragments, You have to set code up differently don't you? I only know how to use normal activities. – Jack Sep 19 '13 at 13:31
  • Ya have to set code differently, different layouts & different files like u r doing in activities... – Anil kumar Sep 19 '13 at 13:41
  • Hey Jack send ur mail Id, I will send u some sample code, it will helps u – Anil kumar Sep 19 '13 at 13:54
  • @Anilkumar jappsenquire@gmail.com Thanks – Jack Sep 19 '13 at 14:05
  • Did you get my mail ID? – Jack Sep 19 '13 at 14:28
  • I sent mail... Just check once, I did sample using Tabs, u modify according to ur requirement.... – Anil kumar Sep 19 '13 at 14:36

0 Answers0