0

我在代码中实现活动组时遇到了一些麻烦。

我的屏幕底部有 4 个单选按钮在此处输入图像描述

一旦其中一个被点击,我希望活动窗口发生变化,但 MainActivity 保持在那里,因此操作栏和单选按钮将保持不变。

因此,以更简单的形式,它就像在活动 A 中启动活动 B、C、D 和 E。

我遇到了一个解决方案,但不知道如何将它实现到我的代码中,因为我已经设置了所有内容。

可能的解决方案:http ://ericharlow.blogspot.co.uk/2010/09/experience-multiple-android-activities.html

任何帮助将不胜感激!

这是我的主要活动:

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" };

};

主要活动 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>
4

0 回答 0