如何使库项目的方法在android的另一个项目中工作?
问题描述:
我有我试图在另一个新项目中使用的项目,我现有的项目的Java代码是在这里:如何使库项目的方法在android的另一个项目中工作?
package com.powergroup.splitview;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class SplitviewActivity extends FragmentActivity implements
Left.OnButtonClickListener {
LinearLayout LEFT, RIGHT, leftfragmentln, rightfragmentln;
Right rightFr;
Left leftFr;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//reduced the Gray Bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
// initializes the objects
initializer();
// sets the size of the two sides, give the ration here
setSize(20, 80);
// sets the colour of the two sides
setColor(Color.BLUE, Color.RED);
}
public void initializer() {
LEFT = (LinearLayout) findViewById(R.id.lnLeft);
RIGHT = (LinearLayout) findViewById(R.id.lnRight);
leftfragmentln = (LinearLayout) findViewById(R.id.lnLeftFragment);
rightfragmentln = (LinearLayout) findViewById(R.id.lnRightFragment);
rightFr = (Right) getSupportFragmentManager().findFragmentById(
R.id.view_right);
leftFr = (Left) getSupportFragmentManager().findFragmentById(
R.id.view_left);
}
public void setColor(int leftColor, int rightColor) {
// for landscape mode
if ((rightFr != null) && rightFr.isInLayout() && (leftFr != null)
&& leftFr.isInLayout()) {
LEFT.setBackgroundColor(leftColor);
RIGHT.setBackgroundColor(rightColor);
} else {
// for portrait mode
RIGHT.setBackgroundColor(rightColor);
}
}
public void setSize(float leftsize, float rightsize) {
// for landscape mode
if ((rightFr != null) && rightFr.isInLayout() && (leftFr != null)
&& leftFr.isInLayout()) {
android.widget.LinearLayout.LayoutParams par1 = (LayoutParams) LEFT
.getLayoutParams();
android.widget.LinearLayout.LayoutParams par2 = (LayoutParams) RIGHT
.getLayoutParams();
par1.weight = rightsize;
par2.weight = leftsize;
}
}
// a method to add view in a blank xml programatically
public void setView(View leftView, View rightView) {
if ((rightFr != null) && rightFr.isInLayout() && (leftFr != null)
&& leftFr.isInLayout()) {
leftfragmentln.addView(leftView);
rightfragmentln.addView(rightView);
} else {
rightfragmentln.addView(rightView);
}
}
@Override
public void onClickButton(String s) {
if ((rightFr != null) && rightFr.isInLayout()) {
rightFr.setText(s);
} else {
Intent intent = new Intent(this, RightActivity.class);
intent.putExtra("value", s);
startActivity(intent);
}
}
}
我在上面的代码做成一个库,并试图在我的另一个项目中使用,其中i可以使用上面的方法。我该怎么办? Plz帮助
答
右键单击您的项目。
转到构建路径>链接源
添加有你想作为一个库使用什么项目路径。
这不是一个解决方案的人,请通读我的问题并试着了解 – 2012-03-30 14:39:57
编译器无法找到com.powergroup.splitview.SplitviewActivity。因此,通过构建路径选项使其可供编译器使用。 – 2012-03-30 14:41:58