0

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?

1
Contributor
1
Reply
4
Views
4 Years
Discussion Span
Last Post by 9tontruck
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.