EditText в GridView: как получить значение из нескольких EditText
Я создалGridView
используя следующий код XML:
и я должен связать этоGridView
со следующим макетом:
и я, наконец, получил эту точку зрения:мой класс адаптера похож на:public class MyGridViewAdapter extends SimpleCursorAdapter {
Cursor cursor;
double productRateValue;
double productDiscountValue;
ImageLoader mImageLoader = new ImageLoader(context);
public MyGridViewAdapter(Context context, int layout, Cursor c,
String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
// TODO Auto-generated constructor stub
//get reference to the row
this.cursor = c;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if(convertView == null)
{
//get reference to the row
view = super.getView(position, convertView, parent);
holder = new ViewHolder();
productRateValue = cursor.getDouble(productCursor.getColumnIndex("rate"));
productDiscountValue = cursor.getDouble(productCursor.getColumnIndex("discount"));
//*** Image ***//
holder.prodImage = (ImageView) view.findViewById(R.id.productImage);
String path = productCursor.getString(productCursor.getColumnIndex(DatabaseHelper.PRODUCT_IMAGES));
mImageLoader.DisplayImage(path, holder.prodImage);
holder.prodName = (TextView) view.findViewById(R.id.productName);
holder.prodName.setText(productCursor.getString(productCursor.getColumnIndex(DatabaseHelper.PRODUCT_NAME)));
holder.prodQty = (EditText) view.findViewById(R.id.productQuantityValue);
holder.prodQty.setText("");
holder.prodRate = (EditText) view.findViewById(R.id.productRateValue);
holder.prodRate.setText(String.valueOf(productRateValue));
holder.prodDisc = (EditText) view.findViewById(R.id.productDiscountValue);
holder.prodDisc.setText(String.valueOf(productDiscountValue));
holder.prodRate.setFocusable(isRateEditable);
holder.prodRate.setEnabled(isRateEditable);
holder.prodDisc.setFocusable(isDiscountEditable);
holder.prodDisc.setEnabled(isDiscountEditable);
/* For set Focus on Next */
if(isRateEditable)
holder.prodQty.setNextFocusDownId(R.id.productRateValue);
else if(isDiscountEditable)
holder.prodQty.setNextFocusDownId(R.id.productDiscountValue);
if(isDiscountEditable)
holder.prodRate.setNextFocusDownId(R.id.productDiscountValue);
holder.prodDisc.setNextFocusDownId(R.id.productQuantityValue);
view.setTag(holder);
}
else
{
holder = (ViewHolder) view.getTag();
}
return view;
}
public class ViewHolder{
ImageView prodImage;
TextView prodName;
EditText prodRate;
EditText prodQty;
EditText prodDisc;
}
}
Теперь мой вопрос, когда я нажимаю наORDER
Tab, я хочу сохранить все данные, в которых "Количество" введено, я переопределитьonPause()
а такжеonStop()
метод для вызоваsaveData()
но что я могу сделать вsaveData()
метод
по моему мнению, я хочу создатьJSONObject
и хранить все значения в виде массива JSON.
Пожалуйста помоги...
Заранее спасибо...