实际上我正在做的是给用户选项来增加所有列表视图项目上的减量产品,如附图所示
我可以将listview项目名称,价格带到下一个屏幕,但应该如何 在按钮单击时,将textview中设置的数量值设置为下一个屏幕 活性
。 ***微调器的数量更新代码在产品适配器中完成
代码:
适配器获取视图: -
public View getView(final int position, View convertView,ViewGroupparent)
{
holder = null;
RowItem rowItem = getItem(position);
mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_details_view, null);
holder = new ViewHolder();
holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.txtPrice = (TextView) convertView.findViewById(R.id.pricee);
holder.add = (Button) convertView.findViewById(R.id.button1);
holder.add_to = (Button) convertView.findViewById(R.id.button3);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.txtPrice.setText("Price $ " + rowItem.getPrice());
holder.txtTitle.setText(rowItem.getTitle());
holder.txtTitle.setTag(position);
holder.add.setTag(position);
holder.sub.setTag(position);
final ViewHolder viewHolderFinal = holder;
final RowItem finalRowItem = rowItem;
holder.add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int quantity = finalRowItem.getQuantity(); // get the quantity
finalRowItem.setQuantity(quantity + 1); // update it by adding 1
viewHolderFinal.txtDesc.setText(finalRowItem.getDesc());
}
});
return convertView;
}
ProductList.java
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class ProductList extends Fragment {
ItemListBaseAdapter apage;
ListView userlist;
RowItem item;
ArrayList<RowItem> sub_cat_arr = new ArrayList<RowItem>();
String u = Login.url + "Products/API/?f=" + "get_product&cat=", id, level;
Button button_show_cart;
int global_position;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewrootView=inflater.inflate
(R.layout.pro_list,container, false);
userlist = (ListView) rootView.findViewById(android.R.id.list);
button_show_cart = (Button) rootView.findViewById(R.id.button_add);
new subcat_data().execute();
apage = new ItemListBaseAdapter(getActivity(),
R.layout.item_details_view, sub_cat_arr);
userlist.setAdapter(apage);
// userlist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
apage.clear();
button_show_cart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
**无法获得每个列表视图
这里选择的数量大于0的数量进入下一个屏幕
**
Intent x = new Intent(getActivity(),Screen2.class);
startActivity(X);
}
});
return rootView;
}
请建议朋友做什么? 感谢