2013-07-01 41 views
1

我想從我的android項目中打開一個庫項目。爲此目的,我一直在使用項目A和項目B(庫項目)從Android項目調用其他庫項目

我在項目A.加入B項目作爲圖書館做了一個演示

下面是我稱之爲:

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

項目表現出一種

<?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> 

在這裏我得到了一個問題 - 活動獲取調用,但用戶界面仍然是相同的ACTI的VITY 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(); 
    } 
} 

項目清單乙

<?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

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

你有兩個選擇:

  1. 添加庫項目在您的項目(android->庫 - >添加庫項目)
  2. 創建該庫項目罐子並添加構建路徑在您的項目 後你可以打電話。