mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Adapter and ShoppingList class for displaying shopping lists
This commit is contained in:
parent
27f22a9724
commit
afe15703ee
@ -82,6 +82,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||||
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
|
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
|
||||||
NavigationUI.setupWithNavController(navigationView, navController);
|
NavigationUI.setupWithNavController(navigationView, navController);
|
||||||
|
|
||||||
// Handle search button click
|
// Handle search button click
|
||||||
ImageButton searchButton = (ImageButton) findViewById(R.id.searchButton);
|
ImageButton searchButton = (ImageButton) findViewById(R.id.searchButton);
|
||||||
searchButton.setOnClickListener(new View.OnClickListener() {
|
searchButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|||||||
@ -0,0 +1,56 @@
|
|||||||
|
package com.example.listify.adapter;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import com.example.listify.R;
|
||||||
|
import com.example.listify.model.ShoppingList;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class DisplayShoppingListsAdapter extends BaseAdapter {
|
||||||
|
private Activity activity;
|
||||||
|
private ArrayList<ShoppingList> lists;
|
||||||
|
private LayoutInflater inflater;
|
||||||
|
|
||||||
|
public DisplayShoppingListsAdapter(Activity activity, ArrayList<ShoppingList> lists){
|
||||||
|
this.activity = activity;
|
||||||
|
this.lists = lists;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return lists.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(int position) {
|
||||||
|
return lists.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
if (inflater == null) {
|
||||||
|
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
}
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = inflater.inflate(R.layout.search_list_item, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShoppingList curList = lists.get(position);
|
||||||
|
|
||||||
|
TextView tvListName = (TextView) convertView.findViewById(R.id.shopping_list_name);
|
||||||
|
tvListName.setText(curList.getName());
|
||||||
|
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package com.example.listify.model;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class ShoppingList extends ArrayList<Product> {
|
||||||
|
private ArrayList<Product> list;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public ShoppingList(String name) {
|
||||||
|
list = new ArrayList<Product>();
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Product get(int position) {
|
||||||
|
return this.list.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return list.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return list.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(@Nullable Object o) {
|
||||||
|
return list.contains(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int indexOf(@Nullable Object o) {
|
||||||
|
return list.indexOf(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(Product product) {
|
||||||
|
return list.add(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Product remove(int index) {
|
||||||
|
return list.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(@Nullable Object o) {
|
||||||
|
return list.remove(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAll(@NonNull Collection<? extends Product> c) {
|
||||||
|
return list.addAll(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/shopping_list_name"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
</RelativeLayout>
|
||||||
Loading…
Reference in New Issue
Block a user