/** * Pushes data into list adapter. * * @param data the data to push */ @UiThread protected void updateListView(PaginatedList<Artist> data) { if (loadingProgressBar.getVisibility() == View.VISIBLE) loadingProgressBar.setVisibility(View.INVISIBLE); if (data.getCount() <= 0) { Toast.makeText(this, "No singer was found", Toast.LENGTH_LONG).show(); this.finish(); return; } if (artistsFound == null) artistsFound = new PaginatedList<Artist>(data); else artistsFound.addItems(data.getItems()); list = (ListView) findViewById(android.R.id.list); // If the adapter doesn't exist, we create one with the initial data. // If it exists, we update it. int currentPosition = -1; if (adapter == null) { adapter = new ArtistsListAdapter(this, data.getItems()); } else { currentPosition = list.getFirstVisiblePosition(); adapter.addItems(data.getItems()); } list.setAdapter(adapter); list.setSelectionFromTop(currentPosition + 1, 0); if (artistsFound.getPaging().isLast()) list.removeFooterView(loadMoreProgress); this.isLoading = false; }
// OnItemClickListener public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (view.getId() == android.R.id.progress) { // If the user clicked at the load more progress indicator, // do nothing. return; } // Verifying internet connection... if (!ConnectionManager.isConnected(this)) { Toast.makeText( this, this.getString(R.string.message_no_internet_connection), Toast.LENGTH_LONG) .show(); } Intent intent = new Intent(this, ArtistViewerActivity_.class); Artist artist = (Artist) adapter.getItem(position); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Artist.KEY, artist); startActivity(intent); }