Shawn Low
Shawn Low

Reputation: 13

ListView doesnt appear after called finish(), and reopen

I'm getting data through PHP and set to listview.. First i open the application , the listview will show out, but after called finish and reopen the application , the listview will not appear and need to call refresh to make it re-appear ..

FeedAdapter:

 public View getView(int position, View convertView, ViewGroup parent){


    View row = inflater.inflate(R.layout.row_feed, parent, false);
    TextView username = (TextView) row.findViewById(R.id.txtUsername);

    MovieFeed moviefeed = localmovies.get(position);

    username.setText(moviefeed.getUsername());


    return row;
}

Tab1 fragment with listview

 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.tab_1, container, false);

    tweetListView = (ListView) v.findViewById(R.id.tweetList);


        urlString = "http://idonno.net/G.php"; //json url
        new ProcessJSON().execute(urlString);
        tweetItemArrayAdapter = new FeedAdapter(getActivity(), localmovies);
     tweetListView.setAdapter(tweetItemArrayAdapter);

return v;


}

Upvotes: 0

Views: 64

Answers (1)

Sanf0rd
Sanf0rd

Reputation: 3664

You should implement an asyncTask and make sure that you really have the data before instantiating the listview. Like in this example with a anonymous inner class.

 @Override
 protected void onPostExecute(String result){
    progressDialog.dismiss();
    runOnUiThread(new Runnable(){
        public void run(){
            final ListView lv1 = (ListView) findViewById(R.id.listings);
            lv1.setAdapter(new CustomListAdapter(YourActivity.this, shares));
        }
    });

}

If you update the list anytime you should call notifyDataSetChanged()on your adapter.

You could separate the asyncTask too like the accepted answer for this question How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?

Upvotes: 1

Related Questions