Esempio n. 1
0
  public void initializeView(
      int newFitLogId, String workoutName, String referenceId, boolean editable, View button) {
    mFitLogId = newFitLogId;
    if (referenceId == null) {
      mRootFitLog = new FitLog(mFitLogId, 0);
    } else {
      ParseQuery<FitLog> refQuery = new ParseQuery<FitLog>("FitLog");
      refQuery.whereEqualTo("objectId", referenceId);
      ParseQuery<FitLog> query = new ParseQuery<FitLog>("FitLog");
      query.whereMatchesKeyInQuery("user", "user", refQuery);
      query.whereMatchesKeyInQuery("fitLogId", "fitLogId", refQuery);
      query.addAscendingOrder(FitLog.INDEX);
      try {
        List<FitLog> list = query.find();
        List<FitLog> newList = new LinkedList<FitLog>();
        Iterator<FitLog> it = list.iterator();
        while (it.hasNext()) {
          newList.add(it.next().getNewFitLog(newFitLogId));
        }

        mRootFitLog = FitLog.buildHierarchy(newList);
      } catch (Exception e) {
        // TODO
        e.printStackTrace();
      }
    }
    mRootFitLog.put(FitLog.EXERCISE, workoutName);
    addView(mRootFitLog.createView(getContext(), editable));
    setVisibility(View.VISIBLE);
    button.setVisibility(View.GONE);

    this.addOnLayoutChangeListener(this);
  }
    @Override
    protected Void doInBackground(String... params) {
      // TODO Auto-generated method stub
      /*try {
      	Thread.sleep(1000);
      } catch (InterruptedException e1) {
      	// TODO Auto-generated catch block
      	e1.printStackTrace();
      }*/

      // categorylinearlayout = (LinearLayout) getView().findViewById(R.id.categorylinearlayout1);
      listview = (ListView) getView().findViewById(R.id.categorylistview);
      final TextView lblcategory = (TextView) getView().findViewById(R.id.lblcategory1);
      final Context context;
      final String value = params[0];

      ParseQuery<ParseObject> categoryquery = ParseQuery.getQuery("Category");
      categoryquery.whereEqualTo("name", value);
      ParseQuery<ParseObject> productquery = ParseQuery.getQuery("Product");
      productquery.whereMatchesKeyInQuery("categoryid", "objectId", categoryquery);
      productquery.findInBackground(
          new FindCallback<ParseObject>() {

            private ProductCategoryAdapter adapter;

            public void done(List<ParseObject> objects, ParseException e) {
              // TODO Auto-generated method stub
              if (e == null) {

                adapter = new ProductCategoryAdapter(getView().getContext(), objects);
                // int i=0;
                listview.setAdapter(adapter);
                lblcategory.setText(value);
                /*	for(ParseObject c:objects){
                	View v = adapter.getView(i, null, null);
                	lblcategory.setText(Integer.toString(i));

                     		//categorylinearlayout.addView(v);

                     		i++;
                }*/

              }
            }
          });
      listview.setOnItemClickListener(
          new OnItemClickListener() {

            private Activity context;

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              // TODO Auto-generated method stub
              ParseObject p = (ParseObject) listview.getItemAtPosition(position);
              Bundle args = new Bundle();
              FragmentManager fragmanager = getFragmentManager();
              Fragment productdetail = new ProductDetailFragment();
              FragmentTransaction fragtrans = fragmanager.beginTransaction();
              args.putString("productid", p.getObjectId());
              productdetail.setArguments(args);
              fragtrans.replace(R.id.content_frame, productdetail).addToBackStack(null).commit();
            }
          });

      return null;
    }