I have two layout xmls.
greeting.xml
main.xml
It's really nub question. I draw greeting layout at first and draw main layout when user clicks a button in the greeting layout. Problem is that components in the main layout are null because they are not drawn yet so I can't initiate components or give event listeners onto them.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_facereader_greeting); //draw greeting layout first
btnStart = (Button) findViewById(R.id.btnStart);
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.activity_facereader_main); //if button is click, main layout is drawn
}
});
ArrayList<Entry> searchResults = GetSearchResults();
ListView lv1 = (ListView) findViewById(R.id.entryList); //ListView in main xml
lv1.setAdapter(new EntryListAdaptor(this, searchResults));
//error around here because ListView is not drawn yet
//I cannot put this code in onClick function because "this" is not onCreate
}
How should I change this?