I have created GridView
using following XML code:
grid_layout.xml
<GridView
android:id="@+id/productList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dp"
android:layout_marginBottom="10dp"
android:drawSelectorOnTop="true"
android:fastScrollEnabled="true"
android:horizontalSpacing="10dp"
android:listSelector="@drawable/list_view_selector"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
<!-- android:listSelector="@drawable/list_view_selector" is not affecting -->
and I have bind that GridView
with following layout:
grid_inner_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/productChildView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/login_bg"
android:gravity="center"
android:padding="5dp" >
<ImageView
android:id="@+id/productImage"
android:layout_width="100dp"
android:layout_height="150dp"
android:layout_alignLeft="@+id/productName"
android:layout_alignRight="@+id/productName"
android:contentDescription="@string/date_desc"
android:src="@drawable/ic_date" />
<TextView
android:id="@+id/productName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/productImage"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:ellipsize="marquee"
android:gravity="center_horizontal"
android:singleLine="true"
android:text="@string/product_name"
android:textColor="@android:color/black"
android:textSize="@dimen/list_item_text_size" />
<LinearLayout
android:id="@+id/productEditTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/productName" >
<EditText
android:id="@+id/productRateValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/edit_text_holo_light"
android:gravity="right"
android:hint="@string/hint_rate"
android:inputType="number"
android:nextFocusRight="@+id/productDiscountValue"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" >
</EditText>
<EditText
android:id="@+id/productDiscountValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/edit_text_holo_light"
android:gravity="right"
android:hint="@string/hint_disc"
android:inputType="number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
</LinearLayout>
<EditText
android:id="@+id/productQuantityValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/productEditTextView"
android:layout_marginRight="5dp"
android:background="@drawable/edit_text_holo_light"
android:gravity="right"
android:hint="@string/hint_quantity"
android:inputType="number"
android:nextFocusRight="@+id/productRateValue"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" >
<requestFocus />
</EditText>
</RelativeLayout>
and i got finally this view:
my Adapter Class is like:
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;
}
}
Now my question is when I click on ORDER
Tab, i want to save all the data in which "Quantity" is entered, i have override onPause()
and onStop()
method to call saveData()
but what can i do in saveData()
method
as per my view i want to create
JSONObject
and store all value as an Array of JSON.
Please Help...
Thanks in advance...
Do this way..
you will get output jsonobject with prodname and it's entered qty here.
With My Question i am success to save data in
JSONArray
but got Again This Problemand Finally i found solution:
I have used
BaseAdapter
instead ofSimpleCursorAdapter
MyGridViewAdapter.java
I have converted
Cursor
in toArrayList<ProductItems>
:Any Suggestion would be Appreciated :)
Thanks...