Home Dynamic linearlayout in DialogFragment for Android (Java)
Reply: 0

Dynamic linearlayout in DialogFragment for Android (Java)

user2121
1#
user2121 Published in May 26, 2018, 9:37 pm

I set the view to a layout with scrollview and linearlayout, and set a button added in the title to add new row in the linearlayout, but new row does not appear, any tips? I plan to use this DialogFragment as a BLE search, is this a good way to solve it?

public class BLE_Devices_Fragment extends DialogFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout to use as dialog or embedded fragment
        return inflater.inflate(R.layout.fragment_ble_devices, container, false);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();


        LinearLayout layout = inflater.inflate(R.layout.fragment_ble_devices, null).findViewById(R.id.deviceList);

        View titleView = inflater.inflate(R.layout.bluetoothscan_title, null, false);
        ImageButton syncBLEButton = titleView.findViewById(R.id.syncBLEButton);
        syncBLEButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                layout.addView(new Button(layout.getContext()));
            }
        });

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });

        builder.setCustomTitle(inflater.inflate(R.layout.bluetoothscan_title, null)).create();
        builder.setView(inflater.inflate(R.layout.fragment_ble_devices, null));
        // Create the AlertDialog object and return it
        return builder.create();
    }


}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306308 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO