suresh vanga
suresh vanga

Reputation: 71

How to hide the TextView after 2 Seconds when list item clicked.?

I am using TextView in my Adapter Class, when I click the list item I display a TexView beside the list item. But I need to hide that TextView after 2 seconds..?

I used Timer functionality but it not working in Adapter Class.

Please help me find a good solution.

Here is my code:

static class ViewHolder {
    TextView name;
    TextView time;
    ImageView check;
    TextView full_name;

}

public static class Clockin_Adapter extends ArrayAdapter<DataItem> {

    .
    .
    .
    .
    //in getView() method..

    holder.name.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {



            holder.full_name.setVisibility(View.VISIBLE);
            holder.full_name.setText(employeeList[position]);

            return false;
        }
    });

    // need to hide **holder.full_name** textView after x seconds..

}

Upvotes: 0

Views: 1433

Answers (1)

Chirag
Chirag

Reputation: 56925

Create on Handler class and put your textview hide code in that and call that handler using postDelayed Method.

// Declare handler

private Handler mHandler = new Handler(); 

private Runnable mUpdateTimeTask = new Runnable() 
 {
    public void run() 
    {
         // Code to hide textview          
    }
}

Call Handler using postDelayed Method.

mHandler.postDelayed(mUpdateTimeTask, 2000); // 2 Seconds

Upvotes: 3

Related Questions