I'm confused about Custom Views. I have noticed that when I define an Android application this way:
----- Whatever.java -----
public class Whatever extends Activity {
private SecondView mySecondView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mySecondView = new SecondView(this.getApplicationContext());
}
----- SecondView.java -----
public class SecondView extends View {
public EditText txt1;
public SecondView(Context context) {
super(context);
// doing text assignment did nothing here.
txt1 = (EditText) findViewById(R.id.EditText01);
txt1.setWidth(200);
}
}
When I run this or anything like this, the SecondView doesn't do anything. Once I had an onDraw event defined and that did nothing either.
Instead of this line:
mySecondView = new SecondView(this.getApplicationContext());
I've tried this line:
mySecondView = (SecondView) findViewById(R.id.SecondView)
with "SecondView" being defined in the XML file with a tag like the following:
<my.package.SecondView ... ... />
but that seems to cause two problems:
1) The application hangs, causing a Force close situation
2) In the XML Outline editor, there's a Null reference exception where the layout normally appears.
My questions are:
Q1) What's the best way to have an Activity in one java file and a View in another file? Why would you want to? Is this a custom View situation?
Q2) Why is there no way to have the package-qualified Custom View tag in the XML Outline editor? (Currently, you have to type it in source.)
Q3) In which situations would you want to have multiple Custom Views?

