Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

RelativeLayout with button #53

Closed
tommyim opened this issue Jul 12, 2017 · 6 comments
Closed

RelativeLayout with button #53

tommyim opened this issue Jul 12, 2017 · 6 comments

Comments

@tommyim
Copy link

tommyim commented Jul 12, 2017

I trying to create the RelativeLayout class to replace the iconView

final ImageView iconView = (ImageView) inflater.inflate(R.layout.widget_mail, null, false);

like is

final MapRelativeLayout mapView = new MapRelativeLayout(getApplicationContext());

the mapView can show on screen, but the button OnClickListener is not working,
How can I fix it?

and there is my MapRelativeLayout class

public class MapRelativeLayout extends RelativeLayout {
    LayoutInflater mInflater;
    public MapRelativeLayout(Context context){
        super(context);
        mInflater = LayoutInflater.from(context);
        init();
    }

    public void init()
    {
        View v = mInflater.inflate(R.layout.widget_map_relative_layout, this, true);
       Button btn = findViewById(R.id.button);
        btn.setText("Testing");
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("TEST", "Testing");
            }
        });
    }
}
@YoshihideSogawa
Copy link
Contributor

FloatingView executes a click event only for the top level view.
Therefore, please bridge the click event from MapViewRelativeView to Button.

public class MapRelativeLayout extends RelativeLayout{
    LayoutInflater mInflater;
    public MapRelativeLayout(Context context) {
        super(context);
        mInflater = LayoutInflater.from(context);
        init();
    }

    public void init() {
        View v = mInflater.inflate(R.layout.widget_map_relative_layout, this, true);
        final Button btn = (Button) findViewById(R.id.button);
        btn.setText("Testing");
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("TEST", "Testing");
            }
        });

        // Added:MapRelativeLayout's click
        setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // call button event
                btn.performClick();
            }
        });
    }
}

@tommyim
Copy link
Author

tommyim commented Jul 13, 2017

Thanks YoshihideSogawa, that's work, but if I need to add more button in RelativeLayout, that does not work.

@YoshihideSogawa
Copy link
Contributor

Sample code please

@tommyim
Copy link
Author

tommyim commented Jul 13, 2017

MapRelativeLayout class

public class MapRelativeLayout extends RelativeLayout {
    LayoutInflater mInflater;
    Button btnA;
    Button btnB;
    public MapRelativeLayout(Context context){
        super(context);
        mInflater = LayoutInflater.from(context);
        init();
    }

    public void init()
    {
        View v = mInflater.inflate(R.layout.widget_map_relative_layout, this, true);
        
        btnA = v.findViewById(R.id.buttonA);
        btnA.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("Testing", "buttonA");
            }
        });

        btnB = v.findViewById(R.id.buttonB);
        btnB.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("Testing", "buttonB");
            }
        });
    }
}

@YoshihideSogawa
Copy link
Contributor

FloatingView only supports clicking of one View.
If you have an idea to modify please give me a Pull Request.

@YoshihideSogawa
Copy link
Contributor

#12

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants