我是新手android我有购物清单并在点击添加时在列表中添加按钮我需要将产品添加到购物车页面。如何将产品添加到Android中的购物车。我需要编写按钮动作代码并在网页上获取其所有内容。
自定义列表适配器
{{#each employees}}
{{!--Modal--}}
<div id="name={{firstname}}{{lastname}}&referrer=website" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Information ... -->
</div>
</div>
{{/each}}
主要活动
public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Movie> movieItems;
private CustomListAdapter listener;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public CustomListAdapter(Activity activity, List<Movie> movieItems) {
this.activity = activity;
this.movieItems = movieItems;
this.listener = listener;
}
@Override
public int getCount() {
return movieItems.size();
}
@Override
public Object getItem(int location) {
return movieItems.get(location);
}
@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.list_row, null);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
NetworkImageView thumbNail = (NetworkImageView) convertView
.findViewById(R.id.thumbnail);
TextView title = (TextView) convertView.findViewById(R.id.title);
TextView rating = (TextView) convertView.findViewById(R.id.rating);
//TextView genre = (TextView) convertView.findViewById(R.id.genre);
TextView year = (TextView) convertView.findViewById(R.id.releaseYear);
Button btnAddToCart = (Button) convertView
.findViewById(R.id.btnAddToCart);
btnAddToCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Intent in = new Intent(this, MainActivity.class);
Intent intent = new Intent(CustomListAdapter.this.activity, MainActivity.class);
//Toast.makeText(activity.getApplicationContext(), "Added to Cart.",Toast.LENGTH_LONG).show();
}
});
// getting movie data for the row
final Movie m = movieItems.get(position);
// thumbnail image
thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);
// title
title.setText(m.getTitle());
// rating
rating.setText("Quantity" +
": " + String.valueOf(m.getRating())+"gm");
// genre
String genreStr = "";
for (String str : m.getGenre()) {
genreStr += str + ", ";
}
// genreStr = genreStr.length() > 0 ? genreStr.substring(0,
// genreStr.length() - 2) : genreStr;
//genre.setText(genreStr);
// release year
year.setText("Rs"+"."+String.valueOf(m.getYear()));
btnAddToCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(CustomListAdapter.this.activity, ViewCart.class);
CustomListAdapter.this.activity.startActivity(intent);
//Toast.makeText(activity.getApplicationContext(), "Added to Cart.",Toast.LENGTH_LONG).show();
// listener.onAddToCartPressed(m);
}
});
return convertView;
}
public interface CustomListAdapterListener {
public void onAddToCartPressed(Movie m);
}
}
}