单击使TextView显示并消失

时间:2015-10-19 20:24:19

标签: android onclicklistener

我有两个TextView。我的目标是使第一个TextView可单击。如果单击它,则会显示第二个活动。如果再次单击,它将消失。我点击它后点击了第二个活动,但点击第一个活动后我不知道如何让它消失。

我是这样做的:

1st.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        2nd.setText(R.string.2nd_text);
        }

2 个答案:

答案 0 :(得分:1)

var名称永远不会以数字!!

开头

尝试$('section').height($(window).height()); /*set the class 'active' to the first element this will serve as our indicator*/ $('section').first().addClass('active'); /* handle the mousewheel event together with DOMMouseScroll to work on cross browser */ $(document).on('mousewheel DOMMouseScroll', function (e) { e.preventDefault();//prevent the default mousewheel scrolling var active = $('section.active'); //get the delta to determine the mousewheel scrol UP and DOWN var delta = e.originalEvent.detail < 0 || e.originalEvent.wheelDelta > 0 ? 1 : -1; //if the delta value is negative, the user is scrolling down if (delta < 0) { //mousewheel down handler next = active.next(); //check if the next section exist and animate the anchoring if (next.length) { /*setTimeout is here to prevent the scrolling animation to jump to the topmost or bottom when the user scrolled very fast.*/ var timer = setTimeout(function () { /* animate the scrollTop by passing the elements offset top value */ $('body, html').animate({ scrollTop: next.offset().top }, 'slow'); // move the indicator 'active' class next.addClass('active') .siblings().removeClass('active'); clearTimeout(timer); }, 800); } } else { //mousewheel up handler /*similar logic to the mousewheel down handler except that we are animate the anchoring to the previous sibling element*/ prev = active.prev(); if (prev.length) { var timer = setTimeout(function () { $('body, html').animate({ scrollTop: prev.offset().top }, 'slow'); prev.addClass('active') .siblings().removeClass('active'); clearTimeout(timer); }, 800); } } });

如果您想切换可见性,可以使用:

1st.setVisible(View.INVISIBLE);

答案 1 :(得分:1)

试试这个:

1st.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if(2st.getVisibility==View.INVISIBLE){
              2st.setVisible(View.VISIBLE)
        } else{
            2st.setVisible(View.INVISIBLE)
        }
 }