How to make app:entries attribute dynamic?












0















attr.xml



<declare-styleable name="PaymentCustomView">
<attr name="customViewTitle" format="string" />
<attr name="customViewSubtitle" format="string" />
<attr name="android:entries" />
</declare-styleable>


make_payment.xml



    <com.laterpay.MakePaymentCustomView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/blue_column"
app:customViewSubtitle="100"
app:customViewTitle="Maximum Spending"
app:entries="@{vm.vouchers}"/>


CustomView.java



public class MakePaymentCustomView extends LinearLayout {
private Context _context;
public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
_context = context;
setOrientation(LinearLayout.VERTICAL);
LayoutInflater.from(context).inflate(R.layout.make_payment_custom_layout, this, true);
String title;
String subtitle;
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PaymentCustomView, 0, 0);
try {
title = a.getString(R.styleable.PaymentCustomView_customViewTitle);
subtitle = a.getString(R.styleable.PaymentCustomView_customViewSubtitle);
CharSequence entries = a.getTextArray(R.styleable.PaymentCustomView_android_entries);
if(entries != null){
//do something
Log.d("Entries:",entries.toString());
}
} finally {
a.recycle();
}
// Throw an exception if required attributes are not set
if (title == null) {
throw new RuntimeException("No title provided");
}
if (subtitle == null) {
throw new RuntimeException("No subtitle provided");
}

init(title, subtitle);
}
// Setup views
private void init(String title, String subtitle) {
List<String> categories = new ArrayList<String>();
categories.add("Automobile");
categories.add("Business Services");
categories.add("Computers");
categories.add("Education");
categories.add("Personal");
categories.add("Travel");
TextView titleView = findViewById(R.id.customview_textview_title);
TextView subtitleView = findViewById(R.id.customview_textview_subtitle);
Spinner voucherList = findViewById(R.id.voucherSpinner);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(_context, android.R.layout.simple_spinner_item, categories);
voucherList.setAdapter(dataAdapter);
titleView.setText(title);
subtitleView.setText(subtitle);
}


I would like to populate my Spinner with a set of dynamic data which I get from an API. But the issue is, how can I pass this data into a custom view and populate the spinner (voucherList)?



Activity A will pass some of the data to Activity B which contains this custom view. How can I populate the data into the custom view's spinner?










share|improve this question





























    0















    attr.xml



    <declare-styleable name="PaymentCustomView">
    <attr name="customViewTitle" format="string" />
    <attr name="customViewSubtitle" format="string" />
    <attr name="android:entries" />
    </declare-styleable>


    make_payment.xml



        <com.laterpay.MakePaymentCustomView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/blue_column"
    app:customViewSubtitle="100"
    app:customViewTitle="Maximum Spending"
    app:entries="@{vm.vouchers}"/>


    CustomView.java



    public class MakePaymentCustomView extends LinearLayout {
    private Context _context;
    public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    _context = context;
    setOrientation(LinearLayout.VERTICAL);
    LayoutInflater.from(context).inflate(R.layout.make_payment_custom_layout, this, true);
    String title;
    String subtitle;
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PaymentCustomView, 0, 0);
    try {
    title = a.getString(R.styleable.PaymentCustomView_customViewTitle);
    subtitle = a.getString(R.styleable.PaymentCustomView_customViewSubtitle);
    CharSequence entries = a.getTextArray(R.styleable.PaymentCustomView_android_entries);
    if(entries != null){
    //do something
    Log.d("Entries:",entries.toString());
    }
    } finally {
    a.recycle();
    }
    // Throw an exception if required attributes are not set
    if (title == null) {
    throw new RuntimeException("No title provided");
    }
    if (subtitle == null) {
    throw new RuntimeException("No subtitle provided");
    }

    init(title, subtitle);
    }
    // Setup views
    private void init(String title, String subtitle) {
    List<String> categories = new ArrayList<String>();
    categories.add("Automobile");
    categories.add("Business Services");
    categories.add("Computers");
    categories.add("Education");
    categories.add("Personal");
    categories.add("Travel");
    TextView titleView = findViewById(R.id.customview_textview_title);
    TextView subtitleView = findViewById(R.id.customview_textview_subtitle);
    Spinner voucherList = findViewById(R.id.voucherSpinner);
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(_context, android.R.layout.simple_spinner_item, categories);
    voucherList.setAdapter(dataAdapter);
    titleView.setText(title);
    subtitleView.setText(subtitle);
    }


    I would like to populate my Spinner with a set of dynamic data which I get from an API. But the issue is, how can I pass this data into a custom view and populate the spinner (voucherList)?



    Activity A will pass some of the data to Activity B which contains this custom view. How can I populate the data into the custom view's spinner?










    share|improve this question



























      0












      0








      0








      attr.xml



      <declare-styleable name="PaymentCustomView">
      <attr name="customViewTitle" format="string" />
      <attr name="customViewSubtitle" format="string" />
      <attr name="android:entries" />
      </declare-styleable>


      make_payment.xml



          <com.laterpay.MakePaymentCustomView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/blue_column"
      app:customViewSubtitle="100"
      app:customViewTitle="Maximum Spending"
      app:entries="@{vm.vouchers}"/>


      CustomView.java



      public class MakePaymentCustomView extends LinearLayout {
      private Context _context;
      public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
      super(context, attrs);
      _context = context;
      setOrientation(LinearLayout.VERTICAL);
      LayoutInflater.from(context).inflate(R.layout.make_payment_custom_layout, this, true);
      String title;
      String subtitle;
      TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PaymentCustomView, 0, 0);
      try {
      title = a.getString(R.styleable.PaymentCustomView_customViewTitle);
      subtitle = a.getString(R.styleable.PaymentCustomView_customViewSubtitle);
      CharSequence entries = a.getTextArray(R.styleable.PaymentCustomView_android_entries);
      if(entries != null){
      //do something
      Log.d("Entries:",entries.toString());
      }
      } finally {
      a.recycle();
      }
      // Throw an exception if required attributes are not set
      if (title == null) {
      throw new RuntimeException("No title provided");
      }
      if (subtitle == null) {
      throw new RuntimeException("No subtitle provided");
      }

      init(title, subtitle);
      }
      // Setup views
      private void init(String title, String subtitle) {
      List<String> categories = new ArrayList<String>();
      categories.add("Automobile");
      categories.add("Business Services");
      categories.add("Computers");
      categories.add("Education");
      categories.add("Personal");
      categories.add("Travel");
      TextView titleView = findViewById(R.id.customview_textview_title);
      TextView subtitleView = findViewById(R.id.customview_textview_subtitle);
      Spinner voucherList = findViewById(R.id.voucherSpinner);
      ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(_context, android.R.layout.simple_spinner_item, categories);
      voucherList.setAdapter(dataAdapter);
      titleView.setText(title);
      subtitleView.setText(subtitle);
      }


      I would like to populate my Spinner with a set of dynamic data which I get from an API. But the issue is, how can I pass this data into a custom view and populate the spinner (voucherList)?



      Activity A will pass some of the data to Activity B which contains this custom view. How can I populate the data into the custom view's spinner?










      share|improve this question
















      attr.xml



      <declare-styleable name="PaymentCustomView">
      <attr name="customViewTitle" format="string" />
      <attr name="customViewSubtitle" format="string" />
      <attr name="android:entries" />
      </declare-styleable>


      make_payment.xml



          <com.laterpay.MakePaymentCustomView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/blue_column"
      app:customViewSubtitle="100"
      app:customViewTitle="Maximum Spending"
      app:entries="@{vm.vouchers}"/>


      CustomView.java



      public class MakePaymentCustomView extends LinearLayout {
      private Context _context;
      public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
      super(context, attrs);
      _context = context;
      setOrientation(LinearLayout.VERTICAL);
      LayoutInflater.from(context).inflate(R.layout.make_payment_custom_layout, this, true);
      String title;
      String subtitle;
      TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PaymentCustomView, 0, 0);
      try {
      title = a.getString(R.styleable.PaymentCustomView_customViewTitle);
      subtitle = a.getString(R.styleable.PaymentCustomView_customViewSubtitle);
      CharSequence entries = a.getTextArray(R.styleable.PaymentCustomView_android_entries);
      if(entries != null){
      //do something
      Log.d("Entries:",entries.toString());
      }
      } finally {
      a.recycle();
      }
      // Throw an exception if required attributes are not set
      if (title == null) {
      throw new RuntimeException("No title provided");
      }
      if (subtitle == null) {
      throw new RuntimeException("No subtitle provided");
      }

      init(title, subtitle);
      }
      // Setup views
      private void init(String title, String subtitle) {
      List<String> categories = new ArrayList<String>();
      categories.add("Automobile");
      categories.add("Business Services");
      categories.add("Computers");
      categories.add("Education");
      categories.add("Personal");
      categories.add("Travel");
      TextView titleView = findViewById(R.id.customview_textview_title);
      TextView subtitleView = findViewById(R.id.customview_textview_subtitle);
      Spinner voucherList = findViewById(R.id.voucherSpinner);
      ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(_context, android.R.layout.simple_spinner_item, categories);
      voucherList.setAdapter(dataAdapter);
      titleView.setText(title);
      subtitleView.setText(subtitle);
      }


      I would like to populate my Spinner with a set of dynamic data which I get from an API. But the issue is, how can I pass this data into a custom view and populate the spinner (voucherList)?



      Activity A will pass some of the data to Activity B which contains this custom view. How can I populate the data into the custom view's spinner?







      android android-xml android-xml-attribute






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 8:41









      GianhTran

      1,9701922




      1,9701922










      asked Jan 2 at 7:20









      kylaskylas

      5152519




      5152519
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Your customedView should have an custom adapter or a private variable with the setter method.Then you can stuff your customedView to a popupWindow which Activity B will show.






          share|improve this answer































            0














            Check this

            You will call the REST-API first and then pass that collection/dynamic data which you mention to other activity shown in the link.






            share|improve this answer
























            • What I mean is, how to pass the dynamic data into the app:entries

              – kylas
              Jan 2 at 7:52











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002633%2fhow-to-make-appentries-attribute-dynamic%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Your customedView should have an custom adapter or a private variable with the setter method.Then you can stuff your customedView to a popupWindow which Activity B will show.






            share|improve this answer




























              1














              Your customedView should have an custom adapter or a private variable with the setter method.Then you can stuff your customedView to a popupWindow which Activity B will show.






              share|improve this answer


























                1












                1








                1







                Your customedView should have an custom adapter or a private variable with the setter method.Then you can stuff your customedView to a popupWindow which Activity B will show.






                share|improve this answer













                Your customedView should have an custom adapter or a private variable with the setter method.Then you can stuff your customedView to a popupWindow which Activity B will show.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 2 at 8:13









                马树忠马树忠

                112




                112

























                    0














                    Check this

                    You will call the REST-API first and then pass that collection/dynamic data which you mention to other activity shown in the link.






                    share|improve this answer
























                    • What I mean is, how to pass the dynamic data into the app:entries

                      – kylas
                      Jan 2 at 7:52
















                    0














                    Check this

                    You will call the REST-API first and then pass that collection/dynamic data which you mention to other activity shown in the link.






                    share|improve this answer
























                    • What I mean is, how to pass the dynamic data into the app:entries

                      – kylas
                      Jan 2 at 7:52














                    0












                    0








                    0







                    Check this

                    You will call the REST-API first and then pass that collection/dynamic data which you mention to other activity shown in the link.






                    share|improve this answer













                    Check this

                    You will call the REST-API first and then pass that collection/dynamic data which you mention to other activity shown in the link.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 2 at 7:25









                    iamrajshahiamrajshah

                    519820




                    519820













                    • What I mean is, how to pass the dynamic data into the app:entries

                      – kylas
                      Jan 2 at 7:52



















                    • What I mean is, how to pass the dynamic data into the app:entries

                      – kylas
                      Jan 2 at 7:52

















                    What I mean is, how to pass the dynamic data into the app:entries

                    – kylas
                    Jan 2 at 7:52





                    What I mean is, how to pass the dynamic data into the app:entries

                    – kylas
                    Jan 2 at 7:52


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002633%2fhow-to-make-appentries-attribute-dynamic%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                    Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                    A Topological Invariant for $pi_3(U(n))$