You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i am trying to use your custom dialog, but i am having a problem. I cannot access the EditText strings, every time i push it to the database it shows up as an empty string like this "". Will you please help? There is no problem with passing hardcoded strings to the database, the only problem is with converting edittext to string and passing it to the database, it just comes up like this "". I think it is something wrong with how i configured my view, i had to guess because i could not find any examples of the custom dialog. here is my code
public class MainActivity extends AppCompatActivity {
private static final int ID_TEXT_INPUT_DIALOG = R.id.fab;
private String mUsername;
private String mPhotoUrl;
private SharedPreferences mSharedPreferences;
private GoogleSignInClient mSignInClient;
private static final String MESSAGE_URL = "http://pantryapp.firebase.google.com/message/";
public static final String ANONYMOUS = "anonymous";
public static final String FOODS_CHILD = "Pantry2";
private DrawerLayout mDrawerLayout;
private EditText mName, mQuantity, mLifecycle;
// Firebase instance variables
private FirebaseAuth mFirebaseAuth;
private FirebaseUser mFirebaseUser;
private DatabaseReference mFirebaseDatabaseReference;
private View PrivateChatsView;
FirebaseDatabase database = FirebaseDatabase.getInstance();
private DatabaseReference mRef = database.getReference("foods");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//remove below if it breaks
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Set default username as anonymous.
mUsername = ANONYMOUS;
// Initialize Firebase Auth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();
if (mFirebaseUser == null) {
// Not signed in, launch the Sign In activity
startActivity(new Intent(this, SignInActivity.class));
finish();
return;
} else {
mUsername = mFirebaseUser.getDisplayName();
if (mFirebaseUser.getPhotoUrl() != null) {
mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
}
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar ab = getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.ic_menu);
ab.setDisplayHomeAsUpEnabled(true);
//new child entries
mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) {
setupDrawerContent(navigationView);
}
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
if (viewPager != null) {
setupViewPager(viewPager);
}
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//this is the one with all three fields that works.
showEditDialog();
}
});
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
private void showTextInputDialog(Bundle savedInstanceState) {
new LovelyTextInputDialog(this, R.style.EditTextTintTheme)
.setTopColorRes(R.color.PINK)
.setTitle(R.string.text_input_title)
.setMessage(R.string.text_input_message)
.setIcon(R.drawable.ic_forum)
.setInstanceStateHandler(ID_TEXT_INPUT_DIALOG, new LovelySaveStateHandler())
.setConfirmButton(android.R.string.ok, new LovelyTextInputDialog.OnTextInputConfirmListener() {
@Override
public void onTextInputConfirmed(String text) {
Toast.makeText(MainActivity.this,"Added "+ text, Toast.LENGTH_SHORT).show();
}
})
.setSavedInstanceState(savedInstanceState)
.show();
}
private void showEditDialog(){
final Context context = this;
final LovelyCustomDialog mDialog = new LovelyCustomDialog(context);
mDialog.setView(R.layout.item_donate_option);
LayoutInflater inflater = this.getLayoutInflater();
mDialog.setTopColorRes(R.color.PINK);
mDialog.setTitle(R.string.text_input_title);
mDialog.setInstanceStateHandler(ID_TEXT_INPUT_DIALOG, new LovelySaveStateHandler());
mDialog.show();
mDialog.setListener(R.id.ld_btn_confirm, new View.OnClickListener() {
@Override
public void onClick(View view) {
final View v = getLayoutInflater().inflate(R.layout.item_donate_option, null);
final EditText name = (EditText) v.findViewById(R.id.item_name);
final EditText quantity = (EditText) v.findViewById(R.id.item_quantity);
final EditText lifecycle = (EditText) v.findViewById(R.id.item_lifecycle);
String mName = name.getText().toString().trim();
String mQuantity = quantity.getText().toString().trim();
String mLifecycle = lifecycle.getText().toString().trim();
String id = "1";
Foods food = new Foods(mName, mQuantity, mLifecycle);
String lemon = "lemon";
String quant = "3";
String life = "5";
DatabaseReference foodRef = mRef.child("Pantry");
DatabaseReference newFoodRef = foodRef.push();
newFoodRef.setValue(food);
mRef.child("Pantry").setValue(new Foods(lemon, quant, life));
Snackbar.make(view, "Added a " + food.getmName(), Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
public void writeNewFood(String name, String quantity, String lifecycle) {
Foods foods = new Foods(name, quantity, lifecycle);
mRef.child(name).setValue(foods);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.sample_actions, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
switch (AppCompatDelegate.getDefaultNightMode()) {
case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM:
menu.findItem(R.id.menu_night_mode_system).setChecked(true);
break;
case AppCompatDelegate.MODE_NIGHT_AUTO:
menu.findItem(R.id.menu_night_mode_auto).setChecked(true);
break;
case AppCompatDelegate.MODE_NIGHT_YES:
menu.findItem(R.id.menu_night_mode_night).setChecked(true);
break;
case AppCompatDelegate.MODE_NIGHT_NO:
menu.findItem(R.id.menu_night_mode_day).setChecked(true);
break;
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.sign_out_menu:
mFirebaseAuth.signOut();
mSignInClient.signOut();
mUsername = ANONYMOUS;
startActivity(new Intent(this, SignInActivity.class));
finish();
return true;
default:
return super.onOptionsItemSelected(item);
case android.R.id.home:
mDrawerLayout.openDrawer(GravityCompat.START);
return true;
case R.id.menu_night_mode_system:
setNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
break;
case R.id.menu_night_mode_day:
setNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
case R.id.menu_night_mode_night:
setNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
case R.id.menu_night_mode_auto:
setNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
break;
}
return super.onOptionsItemSelected(item);
}
Please can you help me i have been working on this for days. Its my first android project and i really need to figure this out. Thank you for your time, You are my last hope.
The text was updated successfully, but these errors were encountered:
I managed to solve this for anyone that is having this issue.
First Inflate your custom View than pass the view inflated to the .setView() method, dont pass your layout R.layout ...
i am trying to use your custom dialog, but i am having a problem. I cannot access the EditText strings, every time i push it to the database it shows up as an empty string like this "". Will you please help? There is no problem with passing hardcoded strings to the database, the only problem is with converting edittext to string and passing it to the database, it just comes up like this "". I think it is something wrong with how i configured my view, i had to guess because i could not find any examples of the custom dialog. here is my code
And here is my layout file
Please can you help me i have been working on this for days. Its my first android project and i really need to figure this out. Thank you for your time, You are my last hope.
The text was updated successfully, but these errors were encountered: