Cannot resolve constructor ArrayAdapter in custom view [duplicate]

Multi tool use
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

marked as duplicate by Rohit5k2, Nilesh Rathod
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.
add a comment |
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

marked as duplicate by Rohit5k2, Nilesh Rathod
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 ofvoucherList
you need to passlayoutId
for your row view. You can use defaultandroid.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
add a comment |
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
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


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
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
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 ofvoucherList
you need to passlayoutId
for your row view. You can use defaultandroid.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
add a comment |
1
Instead ofvoucherList
you need to passlayoutId
for your row view. You can use defaultandroid.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
add a comment |
2 Answers
2
active
oldest
votes
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);
add a comment |
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()
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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);
add a comment |
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);
add a comment |
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);
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);
answered Jan 2 at 6:37


Mahmoud ElshamyMahmoud Elshamy
1561211
1561211
add a comment |
add a comment |
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()
add a comment |
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()
add a comment |
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()
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()
answered Jan 2 at 6:37


Amit GoswamiAmit Goswami
143
143
add a comment |
add a comment |
Gtcve 0a,me,M 3NdE T 2bwKsw k6v5wQ Pa S V
1
Instead of
voucherList
you need to passlayoutId
for your row view. You can use defaultandroid.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