应用程序无响应点击图像

时间:2016-07-15 17:42:40

标签: android onclicklistener

我正在开发一个应用程序,即使我点击图像,该应用程序也会停止响应。我无法弄清楚问题是什么

以下是导致应用无响应的点击监听器

bash-3.1$ npm start

> support-dashboard@1.0.0 start c:\MEAN_project
> concurrently "npm run tsc:w" "node server.js"

[1] Magic happens on port 8080
[0]
[0] > support-dashboard@1.0.0 tsc:w c:\MEAN_project
[0] > tsc -w
[0]
[0] node_modules/angular2/platform/browser.d.ts(78,90): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/application_ref.d.ts(38,88): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/application_ref.d.ts(92,42): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/application_ref.d.ts(151,33): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(23,15): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(25,16): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/di/reflective_provider.d.ts(103,123): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/di/reflective_provider.d.ts(103,165): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/linker/component_resolver.d.ts(8,53): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/component_resolver.d.ts(12,44): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(59,148): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(100,144): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(105,139): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(106,135): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/async.d.ts(27,33): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/async.d.ts(28,45): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
[0] node_modules/angular2/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
[0] node_modules/angular2/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(100,41): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/collection.d.ts(101,22): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/collection.d.ts(102,25): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/lang.d.ts(4,17): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/lang.d.ts(5,17): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/lang.d.ts(71,59): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/promise.d.ts(2,14): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(11,50): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/platform/browser/browser_adapter.d.ts(75,33): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/platform/dom/dom_adapter.d.ts(85,42): error TS2304: Cannot find name 'Map'.
[0] node_modules/rxjs/Observable.d.ts(10,66): error TS2304: Cannot find name 'Promise'.
[0] node_modules/rxjs/Observable.d.ts(66,60): error TS2304: Cannot find name 'Promise'.
[0] node_modules/rxjs/Observable.d.ts(66,70): error TS2304: Cannot find name 'Promise'.
[0] 8:52:59 AM - Compilation complete. Watching for file changes.

适配器类

 holder.ivLike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.d("logFavourite", "like OnClickListener");
                    Log.e("logLike", "count: " + holder.tvNewsCountLike.getText().toString());

                    if (!Utils.isNewsLikedOrFaved(context, postsData, true)) {

                        like(postsData.getNews_id());
                        Utils.likeOrFavNews(context, postsData, true);
    //                    notifyDataSetChanged();
                        holder.tvNewsCountLike.setText("" + (Integer.parseInt(holder.tvNewsCountLike.getText().toString()) + 1));
                        holder.ivLike.setImageResource(R.drawable.dark);
                    } else {
                        unlike(postsData.getNews_id());
                        Utils.unlikeOrUnfavNews(context, postsData, true);
    //                    notifyDataSetChanged();
                        holder.tvNewsCountLike.setText("" + (Integer.parseInt(holder.tvNewsCountLike.getText().toString()) - 1));
                        holder.ivLike.setImageResource(R.drawable.light);


                    }

                }
            });

Util.class

    public class TestNewsAdapter extends RealmBaseRecyclerViewAdapter<NewsTrend, TestNewsAdapter.PostsViewHolder> {

        public RealmResults<NewsTrend> realmResults;
        public Context context;
        public EventListener eventListener;

        RetrofitInterface restApi;
        static User user;
        static  String fbid;

        public TestNewsAdapter(Context context, RealmResults<NewsTrend> realmResults, boolean automaticUpdate) {
            super(context, realmResults, automaticUpdate);
            this.realmResults = realmResults;
            this.context = context;
        }

        public void setEventListener(EventListener eventListener) {
            this.eventListener = eventListener;
        }

        @Override
        public PostsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            user = TrendingApplication.getInstance().getPrefManager().getUser();

            fbid = user.getId();
            View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_news, viewGroup, false);
            PostsViewHolder mediaViewHolder = new PostsViewHolder(v);
            return mediaViewHolder;
        }

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

            final NewsTrend postsData = getItem(position);

            if (position % 2 == 1) {
                holder.llLeft.setGravity(Gravity.RIGHT);
                holder.llRight.setGravity(Gravity.LEFT);
                holder.ivArrowLeft.setVisibility(View.INVISIBLE);
                holder.ivArrowRight.setVisibility(View.VISIBLE);
            }

            String eventName = postsData.getTitle();
            String eventDate = postsData.getTimestamp();
            holder.sourceName.setText(postsData.getType());

            if (Utils.isNewsLikedOrFaved(context, postsData, true)) {
                holder.ivLike.setImageResource(R.dark);
            } else {
                holder.ivLike.setImageResource(R.drawable.light);
            }

            if (Utils.isNewsLikedOrFaved(context, postsData, false)) {
                holder.ivFavorite.setImageResource(R.drawable.dark_fav);
            } else {
                holder.ivFavorite.setImageResource(R.drawable.light_fav);
            }

            Spanned decodedTitle = Html.fromHtml(eventName);

            if(postsData.getType().equals("Bella Naija")){
                holder.sourceImg.setImageResource(R.drawable.bella);
            }else if(postsData.getType().equals("Punch")){
                holder.sourceImg.setImageResource(R.drawable.punch);
            }else if(postsData.getType().equals("Linda Ikeji")){
                holder.sourceImg.setImageResource(R.drawable.lib);
            }else if(postsData.getType().equals("Pulse")){
                holder.sourceImg.setImageResource(R.drawable.pulse_logo);
            }


            holder.tvCountPageView.setText(postsData.getRead_count() + " Views");
            holder.tvNewsCountLike.setText("" + postsData.getLike_count());

            holder.tvNewsTitle.setText(decodedTitle);
            holder.tvNewsDate.setText(getSplitDate(eventDate));
            String text = postsData.getContent() + "<font color='red'>  <strong>More...</strong></font>";
            holder.tvNewsShortText.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);
           // holder.sourceName.setText(postsData.getType());


                Glide.with(context)
                        .load(postsData.getImage())
                        .centerCrop()
                        .placeholder(R.drawable.tw_logo)
                        .into(holder.ivNewsImage);


            holder.llRight.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View v) {
                    sendReadInfo(postsData.getNews_id());
                    /*Intent in = new Intent(context, WebViewActivity.class);
                    in.putExtra(WebViewActivity.ARG_SEARCH_REQUEST, postsData.getHref());
                    context.startActivity(in);*/
                    new FinestWebView.Builder(context)
                            .theme(R.style.FinestWebViewTheme)
                            .titleDefault("What's Trending")
                            .showUrl(false)
                            .statusBarColorRes(R.color.bluePrimaryDark)
                            .toolbarColorRes(R.color.colorPrimary)
                            .titleColorRes(R.color.finestWhite)
                            .urlColorRes(R.color.colorPrimaryDark)
                            .iconDefaultColorRes(R.color.finestWhite)
                            .progressBarColorRes(R.color.PrimaryDarkColor)
                            .stringResCopiedToClipboard(R.string.copied_to_clipboard)
                            .stringResCopiedToClipboard(R.string.copied_to_clipboard)
                            .stringResCopiedToClipboard(R.string.copied_to_clipboard)
                            .showSwipeRefreshLayout(true)
                            .swipeRefreshColorRes(R.color.bluePrimaryDark)
                            .menuSelector(R.drawable.selector_light_theme)
                            .menuTextGravity(Gravity.CENTER)
                            .menuTextPaddingRightRes(R.dimen.defaultMenuTextPaddingLeft)
                            .dividerHeight(0)
                            .gradientDivider(false)
                            .setCustomAnimations(R.anim.slide_up, R.anim.hold, R.anim.hold, R.anim.slide_down)
                            .show(postsData.getHref());
                }
            });

            holder.ivShare.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    String shareBody =  postsData.getHref();

                    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                    sharingIntent.setType("text/plain");
                    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Trending App");
                    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
                    context.startActivity(Intent.createChooser(sharingIntent, "Paylaş"));
                }
            });


            /*holder.ivFavorite.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.d("logFavourite", "like OnClickListener");


                    if (!Utils.isNewsLikedOrFaved(context, postsData, false)) {
                        Utils.likeOrFavNews(context, postsData, false);
                        notifyDataSetChanged();

                    } else {
                        Utils.unlikeOrUnfavNews(context, postsData, false);
                        notifyDataSetChanged();
                    }

                }
            });*/
            holder.ivLike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.d("logFavourite", "like OnClickListener");
                    Log.e("logLike", "count: " + holder.tvNewsCountLike.getText().toString());

                    if (!Utils.isNewsLikedOrFaved(context, postsData, true)) {

                        like(postsData.getNews_id());
                        Utils.likeOrFavNews(context, postsData, true);
    //                    notifyDataSetChanged();
                        holder.tvNewsCountLike.setText("" + (Integer.parseInt(holder.tvNewsCountLike.getText().toString()) + 1));
                        holder.ivLike.setImageResource(R.drawable.kalp_dolu_kucuk);
                    } else {
                        unlike(postsData.getNews_id());
                        Utils.unlikeOrUnfavNews(context, postsData, true);
    //                    notifyDataSetChanged();
                        holder.tvNewsCountLike.setText("" + (Integer.parseInt(holder.tvNewsCountLike.getText().toString()) - 1));
                        holder.ivLike.setImageResource(R.drawable.kalp_bos_kucuk);


                    }

                }
            });



        }

        private void like(final int newsItemId) {
            setupRestClient();
            Log.e("logfb", "hunk" + fbid);
            restApi.like(newsItemId, fbid, new Callback<ReadStatus>() {
                @Override
                public void success(ReadStatus readStatus, Response response) {
                    Log.e("logLike", "liked, id:" + newsItemId);
                }

                @Override
                public void failure(RetrofitError error) {
                    Log.e("logLike", "fail like");

                }
            });

        }

        private void unlike(final int newsItemId) {
            setupRestClient();

            restApi.unlike(newsItemId, fbid, new Callback<ReadStatus>() {
                @Override
                public void success(ReadStatus readStatus, Response response) {
                    Log.e("logLike", "unliked, id:" + newsItemId);
                }

                @Override
                public void failure(RetrofitError error) {
                    Log.e("logLike", "fail unlike");

                }
            });

        }

        private void setupRestClient() {
            RestAdapter.Builder builder = new RestAdapter.Builder()
                    .setEndpoint("http://voice.atp-sevas.com")
                    .setClient(new OkClient(new OkHttpClient()))
                    .setLogLevel(RestAdapter.LogLevel.FULL);

            RestAdapter restAdapter = builder.build();

            restApi = restAdapter.create(RetrofitInterface.class);
        }

        private void sendReadInfo(int id) {
            setupRestClient();

            restApi.sendReadInfo(id, fbid, new Callback<ReadStatus>() {
                @Override
                public void success(ReadStatus readStatus, Response response) {
                    Log.d("logRead", "Send info send: " + readStatus.isSuccess());

                }

                @Override
                public void failure(RetrofitError error) {
                    Log.d("logRead", "Send info failed");

                }
            });
        }

        @Override
        public NewsTrend getItem(int i) {
            return realmResults.get(i);
        }

        public void swapData(RealmResults<NewsTrend> realmResults) {
            this.realmResults = realmResults;
            notifyDataSetChanged();
        }

        @Override
        public void onAttachedToRecyclerView(RecyclerView recyclerView) {
            super.onAttachedToRecyclerView(recyclerView);
        }

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

        public static class PostsViewHolder extends RecyclerView.ViewHolder {

            public TextView tvNewsDate;
            public TextView tvNewsTitle;
            public TextView tvNewsShortText;
            public TextView sourceName;
            public ImageView sourceImg;

            RelativeLayout postContentHolder;



            public LinearLayout llLeft;
            public LinearLayout llRight;

            public ImageView ivArrowLeft;
            public ImageView ivArrowRight;

            public ImageView ivNewsImage;

            public ImageView ivShare;

            public ImageView ivFavorite;
            public ImageView ivLike;

            public TextView tvCountPageView;
            public TextView tvNewsCountLike;

            PostsViewHolder(View itemView) {
                super(itemView);
                postContentHolder = (RelativeLayout) itemView.findViewById(R.id.postContentHolder);
                ivNewsImage = (ImageView) itemView.findViewById(R.id.ivNewsImage);
                ivArrowLeft = (ImageView) itemView.findViewById(R.id.ivArrowLeft);
                ivArrowRight = (ImageView) itemView.findViewById(R.id.ivArrowRight);
                llLeft = (LinearLayout) itemView.findViewById(R.id.llLeft);
                llRight = (LinearLayout) itemView.findViewById(R.id.llRight);

                ivShare = (ImageView) itemView.findViewById(R.id.ivShare);
                sourceImg = (ImageView) itemView.findViewById(R.id.sourceImg);
                sourceName = (TextView) itemView.findViewById(R.id.sourceName);
                tvNewsTitle = (TextView) itemView.findViewById(R.id.tvNewsTitle);
                tvNewsShortText = (TextView) itemView.findViewById(R.id.tvNewsShortText);
                tvNewsDate = (TextView) itemView.findViewById(R.id.tvNewsDate);

                ivFavorite = (ImageView) itemView.findViewById(R.id.ivFavorite);
                ivLike = (ImageView) itemView.findViewById(R.id.ivLike);

                tvNewsCountLike = (TextView) itemView.findViewById(R.id.tvNewsCountLike);
                tvCountPageView = (TextView) itemView.findViewById(R.id.tvCountPageView);

            }
        }

        public interface EventListener {
            void onItemClick(final View view, NewsTrend postsData);
        }

        @Override
        public int getItemViewType(int position) {
            return position;
        }

        public String getSplitDate(String dateString){

            return dateString;
        }


        public String getSmallDescp(String descp){
            String text = descp + "<font color='#f2732f'>  <strong>more...</strong></font>";

            return text.substring(0, 50);
        }

    }

0 个答案:

没有答案