<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:keepScreenOn="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/white"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/bg_border_layout"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"></LinearLayout>
<LinearLayout
android:id="@+id/back_btn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<ImageView
android:clickable="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/ic_left_arrow"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="88">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:gravity="center"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="2">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="match_parent"
android:layout_weight="2"
android:layout_height="0dp"
android:src="@drawable/ic_menu_icon"
android:id="@+id/restuarnt_img" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="@dimen/text_size_medium_small"
android:layout_height="match_parent"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/masterName"
android:gravity="center"
android:textStyle="bold"
android:fontFamily="@font/source_sans_pro_bold"
android:textSize="@dimen/text_size_large"
android:text="FruFresh "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_large"
android:text="Master "/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"></LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/ic_fri_logo"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="30">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/bg_corner_radius_layout"
android:layout_weight="2">
<EditText
android:id="@+id/edit_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:inputType="text"
android:layout_marginLeft="10dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:maxLines="1"
android:fontFamily="@font/source_sans_pro_regular"
android:background="#00000000"
android:textSize="@dimen/text_size_small"
android:hint="Search item"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="25">
<TextView
android:clickable="true"
android:focusable="true"
android:visibility="visible"
android:id="@+id/showAll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center_vertical|right"
android:text="Show All"
android:tag="1"
android:layout_marginRight="@dimen/text_size_large"
android:textColor="#D2D2D2"
android:textSize="@dimen/text_size_medium_small"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="20">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:background="@drawable/bg_corner_radius_layout"
android:layout_weight="2">
<EditText
android:id="@+id/edit_from"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="75"
android:inputType="text"
android:layout_marginLeft="10dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:enabled="false"
android:fontFamily="@font/source_sans_pro_regular"
android:maxLines="1"
android:background="#00000000"
android:textSize="@dimen/text_size_small"
android:hint="From"/>
<ImageView
android:id="@+id/date_to"
android:clickable="true"
android:layout_width="0dp"
android:layout_weight="25"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_height="match_parent"
android:src="@drawable/ic_date_picker"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="2">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="20">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:background="@drawable/bg_corner_radius_layout"
android:layout_weight="2">
<EditText
android:id="@+id/edit_to"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="75"
android:enabled="false"
android:inputType="text"
android:layout_marginLeft="10dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:maxLines="1"
android:fontFamily="@font/source_sans_pro_regular"
android:background="#00000000"
android:textSize="@dimen/text_size_small"
android:hint="To"/>
<ImageView
android:id="@+id/date_From"
android:clickable="true"
android:layout_width="0dp"
android:layout_weight="25"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_height="match_parent"
android:src="@drawable/ic_date_picker"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="2">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D2D2D2"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="horizontal"
>
<TextView
android:id="@+id/sno"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="S.no"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/orderno"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="4"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="Item"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:layout_gravity="center"
android:gravity="right"
android:layout_height="match_parent"
>
<Spinner
android:id="@+id/Caterogryspinner"
android:layout_width="wrap_content"
android:spinnerMode="dropdown"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:layout_height="match_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/customerdeatils"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.5"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="Quantity"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/amount"
android:layout_width="0dp"
android:layout_weight="1.5"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="Amount"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D2D2D2"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="@dimen/text_size_small"
android:layout_weight="7.25">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/orderDetailsdependsitem"
android:listSelector="@android:color/transparent"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"></ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
2.:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/sno"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="S.no"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/itemData"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="Order No."
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/caterogry_name"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="All category"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/quantity"
android:layout_width="0dp"
android:layout_weight="1.5"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="Quantity"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/amount"
android:layout_width="0dp"
android:layout_weight="1.5"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:text="Amount"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D2D2D2"></LinearLayout>
</LinearLayout>
Sourse code:
import android.app.DatePickerDialog; import android.app.Dialog; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.DatePicker; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import com.dfoe.frimaster.DataBaseServices.MasterDB; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; import java.util.Calendar; import de.hdodenhof.circleimageview.CircleImageView; public class ItemReportsActivity extends AppCompatActivity implements View.OnClickListener { ListView orderDetailsdependsitem; MasterDB db; JSONArray jsonArray; ItemReportsListAdapter itemReportsListAdapter; ArrayList<Integer> caterogery_ids; ArrayList<String> caterogery_Name; Spinner Caterogryspinner; TextView masterName,showAll; private int year, month, day; ImageView date_to,date_From; private Calendar calendar; EditText edit_item,edit_to,edit_from; String Todate = "",Fromdate = ""; int caterogryid = 0; LinearLayout back_btn; public String RestaurantImage = ""; CircleImageView restuarnt_img; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title getSupportActionBar().hide(); // hide the title bar setContentView(R.layout.activity_item_reports_layout); orderDetailsdependsitem = (ListView)findViewById(R.id.orderDetailsdependsitem); Caterogryspinner = (Spinner)findViewById(R.id.Caterogryspinner); calendar = Calendar.getInstance(); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH); day = calendar.get(Calendar.DAY_OF_MONTH); masterName = (TextView)findViewById(R.id.masterName); masterName.setText(DashBoard.RestaurantName+ " "); edit_item = (EditText)findViewById(R.id.edit_item); edit_to = (EditText)findViewById(R.id.edit_to); edit_from = (EditText)findViewById(R.id.edit_from); date_to = (ImageView)findViewById(R.id.date_to); date_From = (ImageView)findViewById(R.id.date_From); showAll = (TextView)findViewById(R.id.showAll); back_btn = (LinearLayout)findViewById(R.id.back_btn); back_btn.setOnClickListener(this); showAll.setOnClickListener(this); date_to.setOnClickListener(this); date_From.setOnClickListener(this); db = MasterDB.getInstance(ItemReportsActivity.this); restuarnt_img = (CircleImageView)findViewById(R.id.restuarnt_img); RestaurantImage = db.getRestaurantImage(); Picasso.with(ItemReportsActivity.this).load(RestaurantImage).error(R.drawable.ic_fri_logo).into(restuarnt_img, new Callback() { @Override public void onSuccess() { } @Override public void onError() { } }); edit_item.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { showReportsDependsOnMenuName(edit_item.getText().toString()); } @Override public void afterTextChanged(Editable editable) { } }); Caterogryspinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { showReportOnCaterogry(position); itemReportsListAdapter.notifyDataSetChanged(); // Toast.makeText(getApplicationContext(), Caterogryspinner.getSelectedItem() + " selected", Toast.LENGTH_SHORT).show(); // An item was selected. You can retrieve the selected item using } @Override public void onNothingSelected(AdapterView<?> parent) { // If an option is removed then what to do // or anything else } }); caterogery_ids = db.RestaurantCaterogryDeatils(); caterogery_Name = new ArrayList<>(); caterogery_Name.add("All category"); if(caterogery_ids != null) { if(caterogery_ids.size() > 0) { for(int count = 0; count < caterogery_ids.size(); count++) { JSONObject object = db.RestaurantCaterogryDetailsBasedOnCaterogery(caterogery_ids.get(count)); if(object != null) { if (object.has("caterogery_name")) { try { caterogery_Name.add(object.getString("caterogery_name")); } catch (Exception e) { } } } } } } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item_layout, caterogery_Name); dataAdapter.setDropDownViewResource(R.layout.spinner_item_layout); Caterogryspinner.setAdapter(dataAdapter); //Caterogryspinner.setOnItemSelectedListener(this); super.onCreate(savedInstanceState); } private void showReportOnCaterogry(int caterogry_id) { this.caterogryid = caterogry_id; showAll.setTextColor(Color.parseColor("#D2D2D2")); showAll.setTag(1); edit_to.setText(""); edit_from.setText(""); if(caterogry_id == 0) { jsonArray = db.getItemReports(false,null); if(jsonArray != null) { itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); itemReportsListAdapter.notifyDataSetChanged(); } else { jsonArray = new JSONArray(); itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); itemReportsListAdapter.notifyDataSetChanged(); } } else { ArrayList<Integer> getMenuIDsDependOnCaterogryID = db.getMenuIDsDependOnCaterogryID(caterogry_id); if(getMenuIDsDependOnCaterogryID != null) { if(getMenuIDsDependOnCaterogryID.size() > 0) { jsonArray = db.getItemReports(true, getMenuIDsDependOnCaterogryID); if (jsonArray != null) { itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); itemReportsListAdapter.notifyDataSetChanged(); } else { jsonArray = new JSONArray(); itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); itemReportsListAdapter.notifyDataSetChanged(); } } } } } public void showReportsDependsOnMenuName(String menu_text) { showAll.setTextColor(Color.parseColor("#D2D2D2")); showAll.setTag(1); edit_to.setText(""); edit_from.setText(""); if(menu_text.trim().equals("")) { jsonArray = db.getItemReports(false, null); if (jsonArray != null) { itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } else { jsonArray = new JSONArray(); itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } } else { jsonArray = db.getItemReportsBasedOnMenuName(menu_text); if (jsonArray != null) { itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } else { jsonArray = new JSONArray(); itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } } } // Categary Item Selection public void showReportDependsOnCaterogry(int caterogry_id) { this.caterogryid = caterogry_id; showAll.setTextColor(Color.parseColor("#D2D2D2")); showAll.setTag(1); edit_to.setText(""); edit_from.setText(""); if(caterogry_id == 0) { jsonArray = db.getItemReports(false,null); if(jsonArray != null) { itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } else { jsonArray = new JSONArray(); itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } } else { ArrayList<Integer> getMenuIDsDependOnCaterogryID = db.getMenuIDsDependOnCaterogryID(caterogry_id); if(getMenuIDsDependOnCaterogryID != null) { if(getMenuIDsDependOnCaterogryID.size() > 0) { jsonArray = db.getItemReports(true, getMenuIDsDependOnCaterogryID); if (jsonArray != null) { itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } else { jsonArray = new JSONArray(); itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } } } } } public void showReportDependsOnDates(String fromdate,String todate) { showAll.setTag(2); showAll.setTextColor(Color.parseColor("#006FFF")); edit_to.setText(""+todate); edit_from.setText(""+fromdate); ArrayList<Integer> getMenuIDsDependOnCaterogryID = new ArrayList<>(); if(caterogryid != 0) { getMenuIDsDependOnCaterogryID = db.getMenuIDsDependOnCaterogryID(caterogryid); } jsonArray = db.getItemReportsBasedOnDate(fromdate,todate,getMenuIDsDependOnCaterogryID); if(jsonArray != null) { if(jsonArray.length() > 0) { itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } } else { jsonArray = new JSONArray(); itemReportsListAdapter = new ItemReportsListAdapter(ItemReportsActivity.this); orderDetailsdependsitem.setAdapter(itemReportsListAdapter); } } @Override public void onClick(View view) { switch (view.getId()) { case R.id.date_to: showDialog(998); break; case R.id.date_From: showDialog(999); break; case R.id.showAll: if(view.getTag().toString().equals("2")) { showAll.setTextColor(Color.parseColor("#D2D2D2")); showAll.setTag(1); edit_to.setText(""); edit_from.setText(""); showReportDependsOnCaterogry(0); } break; case R.id.back_btn: finish(); break; } } @Override public void onBackPressed() { // super.onBackPressed(); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub if (id == 998) { return new DatePickerDialog(this, myDateListener, year, month, day); } else if( id == 999) { return new DatePickerDialog(this, myDateListener1, year, month, day); } return null; } private DatePickerDialog.OnDateSetListener myDateListener1 = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub // arg1 = year // arg2 = month // arg3 = day int month = arg2+1; String monthStr = ""+month; String DateStr = ""+arg3; if(month <= 9) { monthStr = "0"+month; } if(arg3 <= 9) { DateStr = "0"+arg3; } String date = arg1 +"-"+ monthStr+"-"+DateStr; Todate = date; if(!Fromdate.trim().equals("")) { showReportDependsOnDates(Fromdate,Todate); } } }; private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub // arg1 = year // arg2 = month // arg3 = day int month = arg2+1; String monthStr = ""+month; String DateStr = ""+arg3; if(month <= 9) { monthStr = "0"+month; } if(arg3 <= 9) { DateStr = "0"+arg3; } String date = arg1 +"-"+ monthStr+"-"+DateStr; Fromdate = date; edit_from.setText(""+Fromdate); } }; public class ItemReportsListAdapter extends BaseAdapter { Context context; public ItemReportsListAdapter(Context context) { this.context = context; } @Override public int getCount() { int count = jsonArray.length(); return count; } @Override public Object getItem(int position) { try { if (jsonArray == null) return null; if (position < 0) return null; return jsonArray.get(position); } catch (Exception ex) { return null; } } @Override public long getItemId(int arg0) { return 0; } @Override public View getView(final int position, View convertView, ViewGroup parent) { TextView sno,itemData,caterogry_name,quantity,amount; final LayoutInflater inflater = (LayoutInflater) ItemReportsActivity.this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.listem_item_for_menu_item_reports_layout, null); sno = (TextView)convertView.findViewById(R.id.sno); itemData = (TextView)convertView.findViewById(R.id.itemData); caterogry_name = (TextView)convertView.findViewById(R.id.caterogry_name); quantity = (TextView)convertView.findViewById(R.id.quantity); amount = (TextView)convertView.findViewById(R.id.amount); int i = position + 1; sno.setText(""+i); try { JSONObject object = jsonArray.getJSONObject(position); if(object.has("menu_id")) { String caterogryname = db.getCaterogryNameByOnMenu_id(object.getInt("menu_id")); caterogry_name.setText(caterogryname); } if(object.has("menu_name")) { String menu_name = db.getMenuNameByOnMenu_idandMenu_price_id(object.getInt("menu_id"),object.getInt("menu_price_id")); itemData.setText(object.getString("menu_name" )+ "(" + menu_name + ")"); } if(object.has("Quantities")) { quantity.setText(""+object.getInt("Quantities")); } if(object.has("price")) { amount.setText(""+object.getDouble("price")); } } catch (Exception ex) { } convertView.setTag(position); return convertView; } } }
No comments:
Post a Comment