Cannot resolve constructor ArrayAdapter in custom view [duplicate]

Multi tool use
Multi tool use












0
















This question already has an answer here:




  • Cannot resolve constructor ArrayAdapter

    3 answers




public class MakePaymentCustomView extends LinearLayout {
public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
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);
} 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>(getContext(), voucherList, categories);
voucherList.setAdapter(dataAdapter);
titleView.setText(title);
subtitleView.setText(subtitle);
}
}


I am trying to set the Array Adapter into the spinner, however I am unable to do so due the following error:




Cannot resolve constructor ArrayAdapter











share|improve this question















marked as duplicate by Rohit5k2, Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 6:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Instead of voucherList you need to pass layoutId for your row view. You can use default android.R.layout.simple_spinner_item

    – nitinkumarp
    Jan 2 at 6:34











  • stackoverflow.com/questions/9891360/…

    – saiedmomen
    Jan 2 at 6:37











  • updating misleading title.

    – Rohit5k2
    Jan 2 at 6:39
















0
















This question already has an answer here:




  • Cannot resolve constructor ArrayAdapter

    3 answers




public class MakePaymentCustomView extends LinearLayout {
public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
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);
} 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>(getContext(), voucherList, categories);
voucherList.setAdapter(dataAdapter);
titleView.setText(title);
subtitleView.setText(subtitle);
}
}


I am trying to set the Array Adapter into the spinner, however I am unable to do so due the following error:




Cannot resolve constructor ArrayAdapter











share|improve this question















marked as duplicate by Rohit5k2, Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 6:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Instead of voucherList you need to pass layoutId for your row view. You can use default android.R.layout.simple_spinner_item

    – nitinkumarp
    Jan 2 at 6:34











  • stackoverflow.com/questions/9891360/…

    – saiedmomen
    Jan 2 at 6:37











  • updating misleading title.

    – Rohit5k2
    Jan 2 at 6:39














0












0








0









This question already has an answer here:




  • Cannot resolve constructor ArrayAdapter

    3 answers




public class MakePaymentCustomView extends LinearLayout {
public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
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);
} 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>(getContext(), voucherList, categories);
voucherList.setAdapter(dataAdapter);
titleView.setText(title);
subtitleView.setText(subtitle);
}
}


I am trying to set the Array Adapter into the spinner, however I am unable to do so due the following error:




Cannot resolve constructor ArrayAdapter











share|improve this question

















This question already has an answer here:




  • Cannot resolve constructor ArrayAdapter

    3 answers




public class MakePaymentCustomView extends LinearLayout {
public MakePaymentCustomView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
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);
} 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>(getContext(), voucherList, categories);
voucherList.setAdapter(dataAdapter);
titleView.setText(title);
subtitleView.setText(subtitle);
}
}


I am trying to set the Array Adapter into the spinner, however I am unable to do so due the following error:




Cannot resolve constructor ArrayAdapter






This question already has an answer here:




  • Cannot resolve constructor ArrayAdapter

    3 answers








android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 6:40









Rohit5k2

14.6k42651




14.6k42651










asked Jan 2 at 6:28









kylaskylas

5002519




5002519




marked as duplicate by Rohit5k2, Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 6:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Rohit5k2, Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 6:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Instead of voucherList you need to pass layoutId for your row view. You can use default android.R.layout.simple_spinner_item

    – nitinkumarp
    Jan 2 at 6:34











  • stackoverflow.com/questions/9891360/…

    – saiedmomen
    Jan 2 at 6:37











  • updating misleading title.

    – Rohit5k2
    Jan 2 at 6:39














  • 1





    Instead of voucherList you need to pass layoutId for your row view. You can use default android.R.layout.simple_spinner_item

    – nitinkumarp
    Jan 2 at 6:34











  • stackoverflow.com/questions/9891360/…

    – saiedmomen
    Jan 2 at 6:37











  • updating misleading title.

    – Rohit5k2
    Jan 2 at 6:39








1




1





Instead of voucherList you need to pass layoutId for your row view. You can use default android.R.layout.simple_spinner_item

– nitinkumarp
Jan 2 at 6:34





Instead of voucherList you need to pass layoutId for your row view. You can use default android.R.layout.simple_spinner_item

– nitinkumarp
Jan 2 at 6:34













stackoverflow.com/questions/9891360/…

– saiedmomen
Jan 2 at 6:37





stackoverflow.com/questions/9891360/…

– saiedmomen
Jan 2 at 6:37













updating misleading title.

– Rohit5k2
Jan 2 at 6:39





updating misleading title.

– Rohit5k2
Jan 2 at 6:39












2 Answers
2






active

oldest

votes


















2














You don't need activity to create ArrayAdapter.



Just create the adapter like this:



ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, categories);





share|improve this answer































    -1














    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), voucherList, categories);You are doing it wrong.
    please check documentation below
    https://developer.android.com/reference/android/widget/ArrayAdapter#public-constructors

    to get context voucherList.getContext()






    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      You don't need activity to create ArrayAdapter.



      Just create the adapter like this:



      ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, categories);





      share|improve this answer




























        2














        You don't need activity to create ArrayAdapter.



        Just create the adapter like this:



        ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, categories);





        share|improve this answer


























          2












          2








          2







          You don't need activity to create ArrayAdapter.



          Just create the adapter like this:



          ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, categories);





          share|improve this answer













          You don't need activity to create ArrayAdapter.



          Just create the adapter like this:



          ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, categories);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 6:37









          Mahmoud ElshamyMahmoud Elshamy

          1561211




          1561211

























              -1














              ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), voucherList, categories);You are doing it wrong.
              please check documentation below
              https://developer.android.com/reference/android/widget/ArrayAdapter#public-constructors

              to get context voucherList.getContext()






              share|improve this answer




























                -1














                ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), voucherList, categories);You are doing it wrong.
                please check documentation below
                https://developer.android.com/reference/android/widget/ArrayAdapter#public-constructors

                to get context voucherList.getContext()






                share|improve this answer


























                  -1












                  -1








                  -1







                  ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), voucherList, categories);You are doing it wrong.
                  please check documentation below
                  https://developer.android.com/reference/android/widget/ArrayAdapter#public-constructors

                  to get context voucherList.getContext()






                  share|improve this answer













                  ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), voucherList, categories);You are doing it wrong.
                  please check documentation below
                  https://developer.android.com/reference/android/widget/ArrayAdapter#public-constructors

                  to get context voucherList.getContext()







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 6:37









                  Amit GoswamiAmit Goswami

                  143




                  143















                      Gtcve 0a,me,M 3NdE T 2bwKsw k6v5wQ Pa S V
                      r,ZgIsIjPk4RzMh,lJJTg5 GCU

                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas