在滚动后,Horizo​​ntalScrollView中的项目的Android单击事件不响应

时间:2011-10-04 13:59:30

标签: android onclick horizontalscrollview

我有一个HorizontalScrollView,我在LinearLayout HorizontalScrollView内添加按钮,并将onClickListener设置为按钮。

当我立即滚动ScrollView 时,点击任何按钮它都不会响应onClick,但滚动后3-5秒,它会响应onClick。

请解释我怎样才能获得这个。我错过了什么吗?

<HorizontalScrollView android:layout_height="wrap_content"
        android:layout_width="600dip"
            android:layout_centerInParent="true" android:gravity="left"
            android:id="@+id/horizontalScrollView1" 

            >
            <LinearLayout android:orientation="horizontal"
                android:id="@+id/llChnnelCategoriesLayout" android:layout_height="wrap_content"
                android:layout_width="wrap_content">
                <TextView android:text="All " android:id="@+id/optionText1"
                    style="@style/CategoriesText"></TextView>
                <TextView android:text="l"
                    style="@style/CategoriesDeviderText"></TextView>
                <TextView android:text="Business News" android:id="@+id/optionText2"
                    style="@style/CategoriesText"></TextView>
                <TextView android:text="l"
                    style="@style/CategoriesDeviderText"></TextView>
                </LinearLayout>
        </HorizontalScrollView>

在Activity中我添加按钮并设置'onClickListener'。

  LinearLayout llChannelCategoriesLayout;
    arrChannelCategory = new String[] {"All Channels","Business News","Entertainment", "News","Cartoon","Music","Other"};
    llChannelCategoriesLayout =(LinearLayout)findViewById(R.id.llChnnelCategoriesLayout);
    llChannelCategoriesLayout.removeAllViews();
    for(int i=0; i<arrChannelCategory.length;i++)
    {
        Button btnCategory = new Button(this);
        TextView tvDevider = new TextView(this);
        tvDevider.setTextAppearance(getApplicationContext(), R.style.ChannelCategoriesDeviderText);


        btnCategory.setTextAppearance(getApplicationContext(), R.style.ChannelCategoriesText);
        //btnCategory.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);

        btnCategory.setText(arrChannelCategory[i]);
        btnCategory.setPadding(Math.round(15*density), Math.round(5*density), Math.round(15*density), Math.round(5*density));
        btnCategory.setClickable(true); 
        btnCategory.setBackgroundColor(Color.TRANSPARENT);

        btnCategory.setId(i+3000);

        if(i != arrChannelCategory.length-1)
        {
            tvDevider.setText("  l  ");
        }

        btnCategory.setOnClickListener( new OnClickListener() {

            @Override
            public void onClick(View v) {
                changeColor(v.getId());
                Log.v("Channel Category Clicked ==","***"+arrChannelCategory[v.getId()-3000]);
            }
        });         

        llChannelCategoriesLayout.addView(btnCategory);     
        llChannelCategoriesLayout.addView(tvDevider);       

    }   

    //changeColor(3000);

}

0 个答案:

没有答案