使用intent将带有提醒的事件添加到日历

时间:2016-07-25 16:50:44

标签: android android-intent calendar android-event

我已将数据转移到新活动 - >从HotelListAdapter.java到HotelPage.java

我设置Log以确保数据已成功传输。 Log现在正在工作并显示我的变量值,但我的TextView和ImageView不显示我的数据(或变量)......

这是我的LogCat:

import { Component, Directive } from '@angular/core';
import {
  FormControl,
  Validators,
  AbstractControl,
  NG_VALIDATORS,
  REACTIVE_FORM_DIRECTIVES
} from '@angular/forms';

function validateRegex(control: FormControl): {[key:string]: boolean} {
  if (!control.value || !control.value.match(/^pee/)) {
    return { 'badName': true };
  }
}
@Directive({
  selector: '[validateRegex]',
  providers: [
    { provide: NG_VALIDATORS, useValue: validateRegex, multi: true }
  ]
})
export class RegexValidator {
}

@Component({
  moduleId: module.id,
  selector: 'validation-errors-template-demo',
  template: `
    <div>
      <h2>Differentiate Validation Errors</h2>
      <h4>Type in "peeskillet"</h4>
      <form #f="ngForm" novalidate>
        <label for="name">Name: </label>

        <input type="text" name="nameCtrl" ngModel validateRegex required />

        <div *ngIf="!f.form.valid && f.form.hasError('badName', ['nameCtrl'])"
             class="error">Name must start with <tt>pee</tt>.</div>

        <div *ngIf="!f.form.valid && f.form.hasError('required', ['nameCtrl'])"
             class="error">Name is required.</div>
      </form>
    </div>
  `,
  styles: [`
    .error {
      border-radius: 3px;
      border: 1px solid #AB4F5B;
      color: #AB4F5B;
      background-color: #F7CBD1;
      margin: 5px;
      padding: 10px;
    }
  `],
  directives: [REACTIVE_FORM_DIRECTIVES, RegexValidator]
})
export class ValidationErrorsTemplateDemoComponent {

}

这是我的HotelListAdapter.java:

07-25 20:57:33.214 4041-4041/ir.homa I/LOG: 2130903040
07-25 20:57:33.214 4041-4041/ir.homa I/LOG:  هما - بندرعباس
07-25 20:57:33.214 4041-4041/ir.homa I/LOG: 187
07-25 20:57:33.214 4041-4041/ir.homa I/LOG: 0

这是HotelPage.java:

        package ir.homa;

    import android.content.Context;
    import android.content.Intent;
    import android.support.v7.widget.PopupMenu;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    import android.widget.RelativeLayout;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.bumptech.glide.Glide;

    import java.util.List;

    /**
     * Created by SMQ on 7/3/2016.
     */
    public class HotelListAdapter extends RecyclerView.Adapter<HotelListAdapter.MyViewHolder> {

        private Context mContext;
        private List<HotelList> hotelList;
        private List<HotelPageList> hotelPage;


        public class MyViewHolder extends RecyclerView.ViewHolder {
            public TextView title, count;
            public ImageView thumbnail, overflow;

            public RelativeLayout card;

            public MyViewHolder(View view) {
                super(view);
                title = (TextView) view.findViewById(R.id.title);
                count = (TextView) view.findViewById(R.id.count);
                thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
                overflow = (ImageView) view.findViewById(R.id.overflow);
                card = (RelativeLayout) view.findViewById(R.id.card);
            }


        }


        public HotelListAdapter(Context mContext, List<HotelList> hotelList) {
            this.mContext = mContext;
            this.hotelList = hotelList;
        }

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)  {
            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.hotel_list, parent, false);


            return new MyViewHolder(itemView);

        }


            @Override
        public void onBindViewHolder(final MyViewHolder holder, final int position) {


            final HotelList hotel = hotelList.get(position);

            holder.title.setText(hotel.getName());
            holder.count.setText(hotel.getNumOfRooms() + " اتاق");

            // loading hotel cover using Glide library
            Glide.with(mContext).load(hotel.getThumbnail()).into(holder.thumbnail);


            holder.overflow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    showPopupMenu(holder.overflow);

                }

            });
    holder.thumbnail.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            int thumbnail1 = hotel.getThumbnail();
            String name1 = hotel.getName();
            int count1 = hotel.getNumOfRooms();
            int position1 = holder.getAdapterPosition();

                switch(holder.getAdapterPosition()) {
                    case 0:
                    Intent intent = new Intent(mContext,HotelPage.class);
                        intent.putExtra("position1", position1);
                        intent.putExtra("thumbnail", thumbnail1);
                        intent.putExtra("name", name1);
                        intent.putExtra("count", count1);
                    mContext.startActivity(intent);
                        break;
                    case 1:
                        Intent intent2 = new Intent(mContext, HotelPage.class);
                        intent2.putExtra("position1", position1);
                        mContext.startActivity(intent2);
                        break;
                }





        }
    });
        }


    /**
     * run intent filter when user clicked on each thumbnails!
     */

    // Create an anonymous implementation of OnClickListener

        /**
         * Showing popup menu when tapping on 3 dots
         */
        private void showPopupMenu(View view) {
            // inflate menu
            PopupMenu popup = new PopupMenu(mContext, view);
            MenuInflater inflater = popup.getMenuInflater();
            inflater.inflate(R.menu.hotel_list_menu, popup.getMenu());
            popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
            popup.show();
        }


        class MyMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {

            public MyMenuItemClickListener() {

            }

            @Override
          public boolean onMenuItemClick(MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    case R.id.action_add_favourite:
                        Toast.makeText(mContext, "به علاقه مندی ها افزوده شد!", Toast.LENGTH_SHORT).show();
                        return true;
                    case R.id.action_hotel_next:
                        Toast.makeText(mContext, "بزودی در دسترس قرار میگیرد!", Toast.LENGTH_SHORT).show();
                        return true;
                    default:
                }
                return false;
            }


        }




        @Override
        public int getItemCount() {
            return hotelList.size();
        }

    }
this is my HotelPageAdapter:

    package ir.homa;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by SMQ on 7/20/2016.
 */
public class HotelPageAdapter extends RecyclerView.Adapter<HotelPageAdapter.MyViewHolder> {

    private Context mContext;
    private List<HotelPageList> hotelPage;





    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView title1, count1;
        public ImageView thumbnail1;
        public RelativeLayout card;
        public MyViewHolder(View view) {
            super(view);
            title1 = (TextView) view.findViewById(R.id.title1);
            count1 = (TextView) view.findViewById(R.id.count1);
            thumbnail1 = (ImageView) view.findViewById(R.id.thumbnail1);
            card = (RelativeLayout) view.findViewById(R.id.card);
        }
    }
    public HotelPageAdapter(Context mContext, List<HotelPageList> hotelPage) {
        this.mContext = mContext;
        this.hotelPage = hotelPage;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.hotel_page, parent, false);
        return new MyViewHolder(itemView);

    }


    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

            HotelPage GetExtras = new HotelPage();

                 final HotelPageList hotel = hotelPage.get(position);

        holder.title1.setText(GetExtras.name);
        holder.count1.setText(GetExtras.count + " اتاق");

        // loading hotel cover using Glide library
        Glide.with(mContext).load(hotel.getThumbnail()).into(holder.thumbnail1);

    }


    @Override
    public int getItemCount() {return hotelPage.size();}
}

这是我的XML(hotel_page.xml):

    package ir.homa;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by SMQ on 7/17/2016.
 */
public class HotelPage extends Activity {
    private Context mContext;
    private RecyclerView recyclerView;
    private HotelPageAdapter adapter;
    private List<HotelPageList> hotelPage;
    private List<HotelList> hotelList;
    private View view;

public String name;
    public int count;
    public int thumbnail;




    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hotel_page);



        hotelPage = new ArrayList<>();
        adapter = new HotelPageAdapter(this, hotelPage);
        prepareHotels();


        try {
            Glide.with(this).load(R.color.bg_main).into((ImageView) findViewById(R.id.backdrop));

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    private int dpToPx(int dp) {
        Resources r = getResources();
        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()));

    }




    private void prepareHotels() {

        final HotelPageList hotel = new HotelPageList();

        Bundle extras = getIntent().getExtras();
        name = extras.getString("name");
        count = extras.getInt("count");
        thumbnail = extras.getInt("thumbnail");

        Log.i("LOG", String.valueOf(thumbnail));
        Log.i("LOG", name);
        Log.i("LOG", String.valueOf(count));
        Log.i("LOG", String.valueOf(hotel.position1));

        HotelPageList b = new HotelPageList( name , count, thumbnail);
        hotelPage.add(b);
        adapter.notifyDataSetChanged();


    }


    // Create an anonymous implementation of OnClickListener

    /**
     * RecyclerView item decoration - give equal margin around grid item
     */
    public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {

        private int spanCount;
        private int spacing;
        private boolean includeEdge;

        public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
            this.spanCount = spanCount;
            this.spacing = spacing;
            this.includeEdge = includeEdge;
        }
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = parent.getChildAdapterPosition(view); // item position
            int column = position % spanCount; // item column

            if (includeEdge) {
                outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
                outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)

                if (position < spanCount) { // top edge
                    outRect.top = spacing;
                }
                outRect.bottom = spacing; // item bottom
            } else {
                outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
                outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f /    spanCount) * spacing)
                if (position >= spanCount) {
                    outRect.top = spacing; // item top
                }
            }
        }
    }
    }

请真正专家回答这个艰难的问题......! &LT; 3

0 个答案:

没有答案