mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Search displays 'No Results' when results are empty
This commit is contained in:
parent
c0f79a70ef
commit
72a201a0fe
@ -13,6 +13,8 @@ import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.listify.adapter.SearchResultsListAdapter;
|
||||
import com.example.listify.data.Chain;
|
||||
import com.example.listify.data.ItemSearch;
|
||||
@ -31,6 +33,7 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
private ListView resultsListView;
|
||||
private MenuItem filterItem;
|
||||
private ProgressBar loadingSearch;
|
||||
private TextView tvNoResults;
|
||||
private SearchResultsListAdapter searchResultsListAdapter;
|
||||
private List<Product> resultsProductList = new ArrayList<>();
|
||||
private List<Product> resultsProductListSorted = new ArrayList<>();
|
||||
@ -64,6 +67,7 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
loadingSearch = (ProgressBar) findViewById(R.id.progress_loading_search);
|
||||
tvNoResults = (TextView) findViewById(R.id.tv_search_no_results);
|
||||
|
||||
// Back button closes this activity and returns to previous activity (MainActivity)
|
||||
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
|
||||
@ -320,10 +324,22 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
}
|
||||
|
||||
// This is called after the search results come back from the server
|
||||
// TODO: Display a "no results" message if nothing is found when searching
|
||||
@Override
|
||||
public void acceptDelivery(Object delivered) {
|
||||
ItemSearch results = (ItemSearch) delivered;
|
||||
|
||||
// Display "no results" message if the search returns none
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (results.getResults().size() == 0) {
|
||||
tvNoResults.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
tvNoResults.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
HashMap<Integer,String> chainNameMap = new HashMap<>();
|
||||
for (int i = 0; i < results.getResults().size(); i++) {
|
||||
|
||||
@ -29,4 +29,14 @@
|
||||
android:divider="@color/list_divider"
|
||||
android:dividerHeight="1dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_search_no_results"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="80dp"
|
||||
android:textSize="20sp"
|
||||
android:text="No Results"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
||||
Loading…
Reference in New Issue
Block a user