public void parseJSONObject(JSONObject jsonObject) { GlobalObject.getInstance().getItemList().clear(); try { int code = jsonObject.getInt(Data.CODE); if (code == 200) { jsonArray_items = jsonObject.getJSONArray(Data.ITEMS); for (int i = 0; i < jsonArray_items.length(); i++) { JSONObject c = jsonArray_items.getJSONObject(i); Item item = new Item(); item.setId(c.getInt(Data.ID)); item.setName(c.getString(Data.NAME)); item.setDesc(c.getString(Data.DESC)); item.setPrice(c.getInt(Data.PRICE)); item.setImage(c.getString(Data.IMAGE)); GlobalObject.getInstance().getItemList().add(item); } } } catch (JSONException e) { e.printStackTrace(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shop); // recieve passed mShop mShop = GlobalObject.getInstance().getPassedShop(); setTitle(mShop.getName()); mListView = (ListView) findViewById(R.id.listView); mEmptyView = (LinearLayout) findViewById(R.id.empty); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); // OnClick Listener for listitem mListView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { GlobalObject.getInstance().setPosition(position); Intent intent = new Intent(activity, ActivityQuantity.class); startActivityForResult(intent, ACTIVITY_QUANTITY_ID); } }); LayoutInflater inflater = getLayoutInflater(); // getting items list by mShop id getItemListAsJSONObject(); mDialog_warning = new AlertDialog.Builder(activity); mDialog_warning .setTitle("Want to go back?") .setMessage(Data.WARNING_MESSAGE_BACK_BUTTON) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mKeyGoBack = true; onBackPressed(); } }) .setNegativeButton("Cancel", null); }
public void setListViewAdapter() { if (GlobalObject.getInstance().getItemList().size() != 0) { mAdapter = new ItemsListAdapter(activity); mListView.setAdapter(mAdapter); } }