Skip to content

Instantly share code, notes, and snippets.

@walteranyika
Created April 16, 2019 11:15
Show Gist options
  • Save walteranyika/fb3777043b8bde52c52fcd8c10f07f54 to your computer and use it in GitHub Desktop.
Save walteranyika/fb3777043b8bde52c52fcd8c10f07f54 to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by walter on 3/10/19.
*/
public class SimpleAdapter extends BaseAdapter {
Context mContext;
ArrayList<Item> mArrayList;
public SimpleAdapter(Context mContext, ArrayList<Item> mArrayList) {
this.mContext = mContext;
this.mArrayList = mArrayList;
}
@Override
public int getCount() {
return mArrayList.size();
}
@Override
public Object getItem(int i) {
return mArrayList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
//MODIFY HERE
view = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);
}
//MODIFY HERE
TextView txtName = view.findViewById(R.id.txtName);
TextView txtQuantity = view.findViewById(R.id.txtQuantity);
TextView txtPrice = view.findViewById(R.id.txtPrice);
Item order=mArrayList.get(i);
//MODIFY HERE
txtName.setText(order.getMeal());
txtQuantity.setText(" x"+order.getQuantity());
txtPrice.setText(order.getTotal()+"");
return view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment