简体   繁体   中英

View.OnFocusChangeListener for HorizonalScrolView?

Does any one have idea how View.OnFocusChangeListener work for HorizontalScrollView ?
I want basicaaly focus event for it's child view ?

any one have idea about it?

I have tried with your problem with following way :

view1 = (LinearLayout) findViewById(R.id.linear1);

view1.setOnFocusChangeListener(new OnFocusChangeListener() {
            public void onFocusChange(View v, boolean hasFocus) {
                    if(hasFocus){
                        Toast.makeText(getApplicationContext(), "view1 Got Focus", Toast.LENGTH_SHORT).show();
                    }
                    else{
                        Toast.makeText(getApplicationContext(), "view1 Lost Focus", Toast.LENGTH_SHORT).show();
                    }
            }
        });

But this is not firing anything, means linear layout is not able to get and lost focus.

So, I tried with setOnClickListener listener in this way :

view1 = (LinearLayout) findViewById(R.id.linear1);

view1.setOnClickListener(new OnClickListener() {            
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "view1 Got Focus", Toast.LENGTH_SHORT).show();
            }
        });

And it works fine.

So, it may be helpful to you to set your logic from your linear layout's setOnClickListener event.

Let me know if you find any confusion or need more help from me.

Hope it helps you.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM