0

我正在尝试从我设置的主要活动组中设置启动子活动。

我是使用活动组的新手,所以我在设置它时遇到了一些麻烦。

我设置了 4 个单选按钮,我希望每个按钮都从我的 MainActivity 打开一个子 Activity。

我收到一条错误消息,指出“OpenCategories 无法解析为类型”和“方法 startChildActivity(String, Intent) 未为类别类型定义”

我知道我在这里做错了,所以需要一些关于设置的指导。

主要活动:

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.GridView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class MainActivity extends ActivityGroup {

private ArrayList<String> mIdList;

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

public void startChildActivity(String Id, Intent intent) {   
      Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

      if (window != null) {
          mIdList.add(Id);
          setContentView(window.getDecorView()); 
      }    
  }

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


        }
    }

};

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

            //Getting error here

            Intent OpenCategories = new Intent(getParent(), Categories.class);
            OpenCategories.putExtra("Flag", 1);
            OpenCategories  = (OpenCategories)getParent();
            Categories.startChildActivity("YOUR_ID", OpenCategories);

        }
    }

};

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

 };
4

1 回答 1

1
// Replace this code 
Intent OpenCategories = new Intent(getParent(), Categories.class);
OpenCategories.putExtra("Flag", 1);
OpenCategories  = (OpenCategories)getParent();
Categories.startChildActivity("YOUR_ID", OpenCategories);

                       To

Intent OpenCategories = new Intent(MainActivity.this, Categories.class);
OpenCategories.putExtra("Flag", 1);
startActivity(OpenCategories);
于 2013-09-19T12:17:50.430 回答