ListView控件 - ListView控件不更新

我试图做Autogrowin /无尽的ListView,但我下载后的数据与ArrayAdapter =更新的问题。

public class ListShowActivity extends ListActivity { private ShowsAdapter m_adapter; private ArrayList<ShowsList> showList = new ArrayList<ShowsList>(); // Adapter private class ShowsAdapter extends ArrayAdapter<ShowsList> { private ArrayList<ShowsList> items = new ArrayList<ShowsList>(); public ShowsAdapter(Context context, int textViewResourceId, ArrayList<ShowsList> items) { super(context, textViewResourceId, items); this.items = items; } public void appendList(ArrayList<ShowsList> results) { if((results != null) && (results.size() != 0)) { m_adapter.add(results.get(0)); m_adapter.notifyDataSetChanged(); Log.i("test", "appendList: "+results.get(0).originalTitle); } } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; TextView tt = null; TextView bt = null; ImageView iv = null; if (v == null){ LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.list_show_item, null); tt = (TextView) v.findViewById(R.id.showOriginalTitle); bt = (TextView) v.findViewById(R.id.showTitle); iv = (ImageView) v.findViewById(R.id.showPoster); } ShowsList item = this.items.get(position); if (item != null) { if(tt != null){ tt.setText(item.originalTitle); } if(bt != null){ bt.setText(item.title); } if(iv != null) { new DownloadImage().downloadImage(item.poster, iv); } } return v; } } // Implement new OnScrollListener public class onScrollLoad implements OnScrollListener { private int lastOffset = 10; private int limit = 10; private int mPrevTotalItemCount = 0; public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (((firstVisibleItem + visibleItemCount) >= totalItemCount) && totalItemCount != mPrevTotalItemCount) { lastOffset = totalItemCount; mPrevTotalItemCount = lastOffset; limit += 1; ArrayList<ShowsList> results = new Api().getShows(lastOffset, limit); m_adapter.appendList(results); //new PagingRequest(m_adapter).execute(lastOffset, limit); Toast.makeText(getApplicationContext(), lastOffset+" / "+limit, Toast.LENGTH_SHORT).show(); } } public void onScrollStateChanged(AbsListView view, int scrollState) { Log.i("test", "onScrollStateChange()"); } } // Implement AsyncTask for download items? /* private static class PagingRequest extends AsyncTask<Integer, Void, ArrayList<ShowsList>> { private ShowsAdapter mAdapter; public PagingRequest(ShowsAdapter adapter) { this.mAdapter = adapter; } protected ArrayList<ShowsList> doInBackground(Integer... params) { return new Api().getShows(params[0], params[1]); } protected void onPostExecute(ArrayList<ShowsList> result) { this.mAdapter.appendList(result); } } */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_shows); TextView tv = (TextView) findViewById(R.id.headerbarText); tv.setText("List Shows"); // Get Items Api a = new Api(); // First 10 items showList = a.getShows(0, 0); if(showList.isEmpty() == false) { //showList = new Api().getShows(0,0); m_adapter = new ShowsAdapter(this, R.layout.list_show_item, showList); setListAdapter(m_adapter); ListView lv = getListView(); lv.setOnScrollListener(new onScrollLoad()); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(ListShowActivity.this, ShowActivity.class); //intent.putExtra("showID", getShowsList.get(position).ID); startActivity(intent); } }); }else{ Toast.makeText(getApplicationContext(), "NoData", Toast.LENGTH_SHORT).show(); } } }

我粘贴代码没有工作的AsyncTask。 在“理论”^^一切正常(appendList登录返回正确的值),但我因为说我有更新ShowsAdapter问题(下载新形象+和插入内容的ListView)

分类:安卓 时间:2015-03-15 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.868 (s). 10 q(s)