【问题标题】:Android loading different contents in the same screen but different activitiesAndroid在同一个屏幕上加载不同的内容但不同的活动
【发布时间】:2011-08-15 08:46:14
【问题描述】:

我是 Android 新手,在使用相同用户界面从同一屏幕调用不同活动时遇到问题。 实际上,我想实现选项卡活动的 d 功能,但我提供按钮而不是选项卡,并且按钮应该像选项卡一样工作。 我无法做到这一点。我在某个地方出错了。 任何人都可以帮助我吗...... HomeScreen 类是:

public class HomeScreen extends Activity implements OnItemClickListener {
    public Integer[] images = { R.raw.mobile, R.raw.note_books, R.raw.ac,
            R.raw.drivers, R.raw.camera, R.raw.home_theaters, R.raw.pda,
            R.raw.tv, R.raw.washing_machines, R.raw.scanners };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grid);
        GridView gv = (GridView) findViewById(R.id.gridV);
        LayoutInflater inflater = getLayoutInflater();

        gv.setAdapter(new GridViewAdapter(images, inflater));
        gv.setOnItemClickListener(this);

        if (StaticUtils.scheckStatus){
            parseData();
        }
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        Intent contents = new Intent(HomeScreen.this, Cat.class);
        contents.putExtra("homescreen", arg2);
        startActivity(contents);
    }

Cat.class 是这样的:

class Cat extends Activity implements OnClickListener{
    private Button mBtnContents, mBtnBrand, mBtnCategory, mBtnBack;
    @Override
    public void onCreate(Bundle si){
        super.onCreate(si);
        setContentView(R.layout.gridtab);
        int i = getIntent().getIntExtra("homescreen", 0);
        mBtnContents=(Button) findViewById(R.id.btnContents);
        mBtnContents.setOnClickListener(this);

        mBtnBrand=(Button) findViewById(R.id.btnBrand);
        mBtnBrand.setOnClickListener(this);

        mBtnCategory=(Button) findViewById(R.id.btnCategory);
        mBtnCategory.setOnClickListener(this);

        mBtnBack=(Button) findViewById(R.id.btnBack);
        mBtnBack.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        if(v==mBtnContents){
            int i = getIntent().getIntExtra("homescreen", 0);
            Intent in=new Intent(Cat.this, Pc.class);
            in.putExtra("homescreen", i);
            startActivity(in);
        } else if(v==mBtnBrand){
            startActivity(new Intent(Cat.this, Sd.class));
        } else if(v==mBtnCategory){
            startActivity(new Intent(Cat.this, Sbc.class));
        } else if(v==mBtnBack){
            startActivity(new Intent(Cat.this, Hs.class));
        }

    }
}

当我点击内容按钮时,它显示详细信息,但当我点击其他按钮时,它不显示任何内容

【问题讨论】:

  • 我完成了部分设计,但功能无法正常工作
  • 那么您面临的具体问题是什么?
  • 响应时间。这是我的问题。当我单击按钮时,它正在启动其他活动。当我单击它们无法正常工作的按钮时,其他活动也具有相同的按钮。
  • 尝试更详细地解释问题,发布一些代码,您可以为此编辑您的问题。根据您已经提供的信息,我无法想象您想要实现什么目标以及有什么问题
  • 嗯,您的代码似乎没问题。您确定您的SdSbcHs 活动没有收到意图吗?如果在这些活动中onCreateonStart 中有finish(),您根本不会看到它们开始。

标签: android android-emulator android-layout android-widget


【解决方案1】:

使用“v.equals(mBtnContents)”代替“v==mBtnContents”,因为 View 是一个对象。

【讨论】:

    猜你喜欢
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多