使用意向的活动联系起来 [英] using of intent for linking activities

查看:111
本文介绍了使用意向的活动联系起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过点击一个按钮,我写了下面的code到我的两个activites链接

I want to link my two activites by clicking on a button i have written the following code

public class IHBCAPTUREActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    ImageView iv;
    TextView tx;
    Button b1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        iv=(ImageView)findViewById(R.id.imageView1);
        tx=(TextView)findViewById(R.id.textView1);
       b1 = (Button) findViewById(R.id.button1);
       b1.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        Intent calIntent;
        **calIntent = new Intent(IHBCAPTUREActivity.this, LoginActivity.class);**
        startActivity(calIntent);           
    }
}

在这一行错误cumes

error cumes in this line

calIntent = new Intent(IHBCAPTUREActivity.this, LoginActivity.class);

LoginActivity.class

LoginActivity不能被解析为一个类型。如何解决呢?

推荐答案

下面是一个简单的code如何加载一个活动到另一个,

here is the simple code how you can load one activity to another,

我已经创造了这样两项活动

i have created two activities like this

package com.rdc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FirstActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first);

        Button btnload = (Button) findViewById(R.id.btn);
        btnload.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent i = new Intent(this, SecondActivity.class);
        startActivity(i);
    }
}


SecondActivity.java

package com.rdc;

import android.app.Activity;
import android.os.Bundle;

public class SecondActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);


    }
}


和我的清单文件


and my manifest file is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.rdc"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".FirstActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity android:name=".SecondActivity"
                  android:label="@string/app_name">
            <intent-filter>                
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>


尝试实现这在你的应用程序,让我知道,如果仍然有任何疑问是存在的。


try to implement this in your app and let me know if still any doubt is there.

这篇关于使用意向的活动联系起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆