我在将活动组实施到我的代码中遇到了一些麻烦。
屏幕底部有4个收音机按钮。
一旦其中一个被点击,我希望活动窗口改变,但MainActivity留在那里,因此Action Bar和Radio Buttons将保留。
因此,在一个更简单的形式中,它就像在活动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>