动态按钮创建需要很长时间才能创建按钮

时间:2016-06-23 10:32:08

标签: android

My screen 我的代码

private void addItem(int i) {
        if(pagination==0) {
            pagination=1;
            buttonList.clear();
            // Create dyamic page button
            int size = (int) Math.ceil(totcheckCount * 1.0 / rowSize);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            for (int j = 0; j < size; j++) {
                final int page_postion;
                page_postion = j;
                final Button btnPage = new Button(getActivity());

                lp.setMargins(5,0,5,0);
                lp.gravity = Gravity.CENTER;
                btnPage.setTextColor(Color.WHITE);
                //btnPage.setTextSize(20.0f);
                btnPage.setId(j);
                btnPage.setBackgroundResource( R.drawable.cmn_btn_style );
                btnPage.setText(String.valueOf(j + 1));
                if(j==0){
                    btnPage.getId();
                    btnPage.setTextColor( Color.RED );
                    ((MainActivity) getActivity())
                            .setActionBarTitle( getActivity().getString( R.string.manage_position) + " " + 1 );
                }
                mLinearScroll = (LinearLayout) getActivity().findViewById(R.id.linear_scroll);
                mLinearScroll.addView(btnPage, lp);
                commonSharedPref.clearAll();
                commonSharedPref.pagination(btnPage.getId(), page_postion);
                btnPage.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        /**
                         * add arraylist item into list
                         */
                        toggleDeSelectAll();
                        feedBackModelList.clear();
                        Button btn_index = (Button) getActivity().findViewById(0);
                        btn_index.setTextColor( Color.WHITE);
                        int page=Integer.valueOf( btnPage.getText().toString() );
                        ((MainActivity) getActivity())
                                .setActionBarTitle(getActivity().getString( R.string.manage_position)+" "+page);
                        int limit=(page-1)*20;
                        if (ApiConstants.isNetworkAvailable( getActivity() )) {
                            Button b = (Button)v;
                            buttonList.add( String.valueOf( b.getId()  ));
                            buttonList.size();
                            if(buttonList.size()>1){
                                int btn_id=Integer.valueOf( buttonList.get( 0 ) );
                                b=(Button) getActivity().findViewById(btn_id);
                                b.setTextColor( Color.WHITE );
                                buttonList.remove( 0 );
                            }
                            getFeedback( limit, page_postion );
                            btnPage.setTextColor( Color.RED );
                        }else{
                            Snackbar snackbar = Snackbar
                                    .make(feedbackpage, R.string.check_network, Snackbar.LENGTH_SHORT);
                            snackbar.show();
                        }
                        commonSharedPref.clearAll();
                        commonSharedPref.pagination(limit, page_postion);
                    }
                });
            }
        }
        //set view
        setView();
    }

错误Logcat ...

  

06-23 06:20:08.221 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:VFY:将操作码0x6f替换为0x008e   06-23 06:20:09.481 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放4418K,47%免费23107K / 43292K,暂停6ms,总计7ms   06-23 06:20:11.231 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1958K,47%免费23181K / 43292K,暂停3ms,总计3ms   06-23 06:20:13.011 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1956K,47%免费23257K / 43292K,暂停3ms,总计3ms   06-23 06:20:14.901 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1958K,47%免费23333K / 43292K,暂停3ms,总计3ms   06-23 06:20:16.591 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1961K,46%释放23410K / 43292K,暂停2ms,总计2ms   06-23 06:20:18.361 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1962K,46%免费23486K / 43292K,暂停2ms,总计2ms   06-23 06:20:20.071 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1961K,46%免费23562K / 43292K,暂停3ms,总计3ms   06-23 06:20:21.841 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1962K,46%免费23639K / 43292K,暂停2ms,总计2ms   06-23 06:20:23.521 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1962K,46%免费23715K / 43292K,暂停3ms,总计3ms   06-23 06:20:24.511 26464-26464 / com.organizer.infinijith.organizer D / dalvikvm:GC_FOR_ALLOC释放1172K,46%免费23743K / 43292K,暂停3ms,总计3ms   06-23 06:20:24.511 26464-26464 / com.organizer.infinijith.organizer

0 个答案:

没有答案