Eugene Shmorgun
Eugene Shmorgun

Reputation: 2065

How to fill the ListView from another class correctly in Android?

My android-app gets List in the one activity, but activity,that contains the LisView for this list is in another class. so:

@Override
protected void onPostExecute(List<CityInfo> result) 
{

    CityArrayDataAdapter cityArrayDataAdapter = new CityArrayDataAdapter(CityParserActivity.this, listCitiesData);  
    super.onPostExecute(result);
}

where CityParserActivity.this is context of my another activity. But Eclipse shows me the next:

No enclosing instance of the type CityParserActivity is accessible in scope

How to fix this problem? Thanks for help.

Possible fix:

CityParserActivity cityParserActivity = new CityParserActivity();
CityArrayDataAdapter cityArrayDataAdapter = new CityArrayDataAdapter(cityParserActivity, listCitiesData);

Upvotes: 0

Views: 286

Answers (1)

Brian Dupuis
Brian Dupuis

Reputation: 8176

How are you expecting to get your instance of CityParserActivity? Are you passing a reference to that somewhere into your enclosing class of this AsyncTask? You can't "wish" a CityParserActivity into existence by trying to cast your this pointer into one if you're not currently in your CityParserActivity.

Upvotes: 1

Related Questions