簡體   English   中英

從Android項目中調用另一個Library項目

[英]Calling the other Library Project from the Android Project

我想從我的android項目中打開一個庫項目。 為此,我使用Project A和Project B(庫項目)進行了演示。

我已將項目B添加為項目A中的庫。

這是我的稱呼方式:

public class ProjectA extends Activity {

    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project);

        btn = (Button)findViewById(R.id.btn_project2);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent LaunchIntent = new Intent(arg0.getContext(),ProjectB.class).setAction(Intent.CATEGORY_LAUNCHER);
                startActivity(LaunchIntent);
            }
        });
    }

項目A的清單

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.projecta.ProjectA"
            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="com.example.projectb.ProjectB" />
    </application>
</manifest>

在這里,我遇到了一個問題-調用了活動,但UI仍然與活動A相同。

public class ProjectB extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project_b);
        Toast.makeText(this, "Project B", 0).show();
    }
}

項目B的清單

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


    <application android:allowBackup="true" >
        <activity android:name="com.example.projectb.ProjectB" />
    </application>

</manifest>

請告訴我為什么我的用戶界面沒有更新

您不能從代碼中調用直接庫項目。

您有兩種選擇:

  1. 在您的項目中添加庫項目(android-> library->添加庫項目)
  2. 為該庫項目創建jar並在調用后在項目中添加構建路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM