我有一个扩展View的类。我还有一个扩展Activity的类,我希望将第一个类添加到加载在Activity类中。
我尝试了以下代码。
package Test2.pack;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
public class Test2 extends Activity {
/** Called when the activity is first created. */
static view v;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
v = (view) View.inflate(Test2.this, R.layout.main2, null);
}catch(Exception e){
System.out.println(" ERR " + e.getMessage()+e.toString());
}
}
}
class view extends View{
public view(Context context) {
super(context);
}
}