Passing dialog selected items to other activities or adapters
up vote
2
down vote
favorite
I am have struggling with trying to add a feature on my project and I need some help on how I can move beyond this step. So I have decided to create a method selectCurrency()
on my preferencesFragment class As you can see I have created a simple Dialog with not more than 6 currencies, what I want to do is once a currency is selected from this dialog I want to display it on my currency adapter.
public class PreferencesFragment extends PreferenceFragment {
final static String items = {"$ - US Dollar", "€ - Euro", "£ - British Pound","IRN - IRN ","A$ - Australian Dollar", " CA$ - Canadian Dollar"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from the XML resource
addPreferencesFromResource(R.xml.pref_general);
//show currency
final Preference currencyPreference = findPreference
(getResources().getString(R.string.setting_category_currency_change_button_key));
currencyPreference.setOnPreferenceClickListener(preference -> {
selectCurrency();
return false;
});
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void selectCurrency() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select Currency")
.setItems(items, (dialog, which) -> {
// String selectedText = items[which].toString();
Toast.makeText(getActivity(), items[which] + " was selected", Toast.LENGTH_SHORT).show();
});
builder.setPositiveButton("OK", null);
builder.setNegativeButton("CANCEL", null);
AlertDialog alertDialog = builder.create();
alertDialog.show();
Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
button.setBackgroundColor(Color.argb(100,100,25,51));
button.setTextColor(Color.WHITE);
}
}
Here is my adapter.
So currently I am using a string which is not right, so how can I get the selected currency from the above fragment to my adapter down here: at holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
public class CurrencyAdapter extends RecyclerView.Adapter<CurrencyAdapter.GeneralViewHolder> {
@Override
public void onBindViewHolder(GeneralViewHolder holder, int position) {
if (getItemViewType(position) == -1) {
MonthSummaryCard holder1 = (MonthSummaryCard) holder;
holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
holder1.setTotalExpensesPerMonth("$ " + Double.valueOf(totalExpenseAmount).toString());
java android dialog alertdialog android-alertdialog
add a comment |
up vote
2
down vote
favorite
I am have struggling with trying to add a feature on my project and I need some help on how I can move beyond this step. So I have decided to create a method selectCurrency()
on my preferencesFragment class As you can see I have created a simple Dialog with not more than 6 currencies, what I want to do is once a currency is selected from this dialog I want to display it on my currency adapter.
public class PreferencesFragment extends PreferenceFragment {
final static String items = {"$ - US Dollar", "€ - Euro", "£ - British Pound","IRN - IRN ","A$ - Australian Dollar", " CA$ - Canadian Dollar"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from the XML resource
addPreferencesFromResource(R.xml.pref_general);
//show currency
final Preference currencyPreference = findPreference
(getResources().getString(R.string.setting_category_currency_change_button_key));
currencyPreference.setOnPreferenceClickListener(preference -> {
selectCurrency();
return false;
});
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void selectCurrency() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select Currency")
.setItems(items, (dialog, which) -> {
// String selectedText = items[which].toString();
Toast.makeText(getActivity(), items[which] + " was selected", Toast.LENGTH_SHORT).show();
});
builder.setPositiveButton("OK", null);
builder.setNegativeButton("CANCEL", null);
AlertDialog alertDialog = builder.create();
alertDialog.show();
Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
button.setBackgroundColor(Color.argb(100,100,25,51));
button.setTextColor(Color.WHITE);
}
}
Here is my adapter.
So currently I am using a string which is not right, so how can I get the selected currency from the above fragment to my adapter down here: at holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
public class CurrencyAdapter extends RecyclerView.Adapter<CurrencyAdapter.GeneralViewHolder> {
@Override
public void onBindViewHolder(GeneralViewHolder holder, int position) {
if (getItemViewType(position) == -1) {
MonthSummaryCard holder1 = (MonthSummaryCard) holder;
holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
holder1.setTotalExpensesPerMonth("$ " + Double.valueOf(totalExpenseAmount).toString());
java android dialog alertdialog android-alertdialog
@Benoit any help?
– Anna Murray
Nov 5 at 21:07
Have you tried using an interface then notify the adapter when the data changes?
– jahson kimulu
Nov 6 at 8:03
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am have struggling with trying to add a feature on my project and I need some help on how I can move beyond this step. So I have decided to create a method selectCurrency()
on my preferencesFragment class As you can see I have created a simple Dialog with not more than 6 currencies, what I want to do is once a currency is selected from this dialog I want to display it on my currency adapter.
public class PreferencesFragment extends PreferenceFragment {
final static String items = {"$ - US Dollar", "€ - Euro", "£ - British Pound","IRN - IRN ","A$ - Australian Dollar", " CA$ - Canadian Dollar"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from the XML resource
addPreferencesFromResource(R.xml.pref_general);
//show currency
final Preference currencyPreference = findPreference
(getResources().getString(R.string.setting_category_currency_change_button_key));
currencyPreference.setOnPreferenceClickListener(preference -> {
selectCurrency();
return false;
});
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void selectCurrency() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select Currency")
.setItems(items, (dialog, which) -> {
// String selectedText = items[which].toString();
Toast.makeText(getActivity(), items[which] + " was selected", Toast.LENGTH_SHORT).show();
});
builder.setPositiveButton("OK", null);
builder.setNegativeButton("CANCEL", null);
AlertDialog alertDialog = builder.create();
alertDialog.show();
Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
button.setBackgroundColor(Color.argb(100,100,25,51));
button.setTextColor(Color.WHITE);
}
}
Here is my adapter.
So currently I am using a string which is not right, so how can I get the selected currency from the above fragment to my adapter down here: at holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
public class CurrencyAdapter extends RecyclerView.Adapter<CurrencyAdapter.GeneralViewHolder> {
@Override
public void onBindViewHolder(GeneralViewHolder holder, int position) {
if (getItemViewType(position) == -1) {
MonthSummaryCard holder1 = (MonthSummaryCard) holder;
holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
holder1.setTotalExpensesPerMonth("$ " + Double.valueOf(totalExpenseAmount).toString());
java android dialog alertdialog android-alertdialog
I am have struggling with trying to add a feature on my project and I need some help on how I can move beyond this step. So I have decided to create a method selectCurrency()
on my preferencesFragment class As you can see I have created a simple Dialog with not more than 6 currencies, what I want to do is once a currency is selected from this dialog I want to display it on my currency adapter.
public class PreferencesFragment extends PreferenceFragment {
final static String items = {"$ - US Dollar", "€ - Euro", "£ - British Pound","IRN - IRN ","A$ - Australian Dollar", " CA$ - Canadian Dollar"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from the XML resource
addPreferencesFromResource(R.xml.pref_general);
//show currency
final Preference currencyPreference = findPreference
(getResources().getString(R.string.setting_category_currency_change_button_key));
currencyPreference.setOnPreferenceClickListener(preference -> {
selectCurrency();
return false;
});
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void selectCurrency() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select Currency")
.setItems(items, (dialog, which) -> {
// String selectedText = items[which].toString();
Toast.makeText(getActivity(), items[which] + " was selected", Toast.LENGTH_SHORT).show();
});
builder.setPositiveButton("OK", null);
builder.setNegativeButton("CANCEL", null);
AlertDialog alertDialog = builder.create();
alertDialog.show();
Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
button.setBackgroundColor(Color.argb(100,100,25,51));
button.setTextColor(Color.WHITE);
}
}
Here is my adapter.
So currently I am using a string which is not right, so how can I get the selected currency from the above fragment to my adapter down here: at holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
public class CurrencyAdapter extends RecyclerView.Adapter<CurrencyAdapter.GeneralViewHolder> {
@Override
public void onBindViewHolder(GeneralViewHolder holder, int position) {
if (getItemViewType(position) == -1) {
MonthSummaryCard holder1 = (MonthSummaryCard) holder;
holder1.setWalletAmountView("$ " + Double.valueOf(walletBalance).toString());
holder1.setTotalExpensesPerMonth("$ " + Double.valueOf(totalExpenseAmount).toString());
java android dialog alertdialog android-alertdialog
java android dialog alertdialog android-alertdialog
edited Nov 5 at 21:03
asked Nov 5 at 17:12
Anna Murray
326
326
@Benoit any help?
– Anna Murray
Nov 5 at 21:07
Have you tried using an interface then notify the adapter when the data changes?
– jahson kimulu
Nov 6 at 8:03
add a comment |
@Benoit any help?
– Anna Murray
Nov 5 at 21:07
Have you tried using an interface then notify the adapter when the data changes?
– jahson kimulu
Nov 6 at 8:03
@Benoit any help?
– Anna Murray
Nov 5 at 21:07
@Benoit any help?
– Anna Murray
Nov 5 at 21:07
Have you tried using an interface then notify the adapter when the data changes?
– jahson kimulu
Nov 6 at 8:03
Have you tried using an interface then notify the adapter when the data changes?
– jahson kimulu
Nov 6 at 8:03
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159067%2fpassing-dialog-selected-items-to-other-activities-or-adapters%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@Benoit any help?
– Anna Murray
Nov 5 at 21:07
Have you tried using an interface then notify the adapter when the data changes?
– jahson kimulu
Nov 6 at 8:03