I would like to get id from dialog box after user select text that populated in dialog box.
How can I populate data with hidden id to dialog box from web service?
Based on the info you gave, I'm guessing you want something like
EditText dialogBox = (EditText) findViewById(R.id.yourDialogBox);
int id = dialogBox.getId();
If you are referring to an actual Dialog object, I do not see any way to directly reference the ID of the dialog other than possibly
yourDialogObject.getOwnerActivity().getTaskId();
Without more info it is hard to say what exactly you are looking for.
Related
I want to get data from database and display it in a text view in a dialog box. In my application, I have a button that when it is clicked, a dialogue box will open. there is a text view in this dialogue box. The text view is going show data from SQLite database. Let me say some more. My database has four fields. one is id, the second title, third is the body and the last one is the translation of the body in another language. In the activity that shows the body, I have a button that when the user clicks on it, a dialogue box will appear that displays the translation. I have used recyclerView to show the titles and bodies.
Thanks in advance.
The easiest approach is to use Room and MVVM like this. The second option is to create a cursor and grab the data from that.
Cursor c = db.rawQuery("SELECT * FROM TABLE_NAME", null);
while(c.moveToNext()){
int id = c.getInt(0);
String title = c.getString(1);
String body = c.getString(2);
String bodyTranslated = c.getString(3);
}
This above code shows that the data is fetched from database and the cursor object is used to get the data and show it on the screen.
If you have problem with showing data in the AlertDialog check this link: Custom Dialog + Sending Information to Activity - Android Studio Tutorial
For RecyclerView related issues check this link: RecyclerView + CardView - Part 1 - LAYOUTS AND CUSTOM OBJECTS - Android Studio Tutorial
How to set the string values on spinner prompt?
The process how I am doing is:
I am able to retrieve the json data(it has only one single value), so I am getting the single text with the help of String.
Later, I am trying to set the string value in Spinner prompt
SP_gender is called as Spinner here. In String gender1, I have texts called as "male"
String gender1 = i.getStringExtra("bundle_CusGender");
SP_gender.setPrompt(gender1);
System.out.println("Check bundle_CusGender = : " + gender1);
When I try to print this, I am getting a value as male
System.out: Check bundle_CusGender = : male
How should I set the single text in spinner Android?
Firstly the setPrompt() methods documentation states:
Sets the prompt to display when the dialog is shown.
Which is pretty vague but internally it calls the setPromptText() method which sets the description on the popup and has the following documentation.
Set hint text to be displayed to the user. This should provide
a description of the choice being made.
So if I am understanding your question correctly you want to set the spinners selected item. You should be using either setSelection(int) or setSelection(int, boolean)
For those to work you would need to give your spinner an adapter if you haven't already. If you don't know how you should check out this answer which explains in more detail.
I'm creating a online table reservation app for android. I need to check the availability of a table once a user selects a particular table. For that I am going to use "Dialogs" in android.
I found that dialogs can be customized. See this tutorial.
So I can add a datepicker and get the time from the user from the customized dialog when he selects a particular table. But can I show the result (eg: availability) using the same dialog.
yes you can your dialog in with more than data and views , you can make flag that's represent the state of the code , if
if(flag =="table"){
// change layout and data
dialog.setContentView(R.layout.datatable);
}
else if (flag =="userform"){
// change the layout to userform
dialog.setContentView(R.layout.userform);
}
Hello people can someone help.
I have designed a dialog in which I would like to have a field box or some sort that when the dialog is called the TYPE & AMOUNT (link) box's will display the data from database on each item. So for this dialog I have made. The user will click drinks button on the activity before the dialog. And the data will fill theses field boxes once called.
My question is what can I use for this data box caller.
You can use TextView or EditText widget (depending on if you want user to just see or edit the data respectively) and you can pull data from SQLite Database.
In my Application I want to Add and Remove View (like Button, or Textview, Checkbox ) by Coding (Programming ).
In Details:
I have One EditText and One Add Button. User Enter Anything in EditText and Press the Add Button then this one is added in bellow LinearLayout, and whether User click on his/her added Button it will going to next LinearLayout.
I get sucess upto this.
but when user click the button in second LinearLayout then it will come back on first Linearlayout. I am getting error Here, i don't know where I made a Mistake.
And I also facing Problem about how can I Store this all. Like User Add 5 Button and closed the application and whenever he/she came back to application I need whatever he/she previously added.
Here is what i done.
http://dynamicandroidview.blogspot.com/2011/12/how-to-add-view-in-android-by-coding.html
Try to create a database table with minimum 2 columns in your case it will be id and buttonText.
Now when user clicks on the add button it will save text to the database and will create the button dynamically below any buttons which are already created before or as a new button.
Now in your onCreate method get the count of text thats stored in database.Some thing like the following code:
DB getData = DB.getInstance();
getData.open(this);
ArrayList<TextHolder> getList = new ArrayList<TextHolder>();
getList = getData.getAllTextFromGeT();
getData.close();
x = genList.size();
Here x will be the number/count of elements that are already stored in the database.Now you can another int say i and using this i and x in the for loop you can create buttons dynamically.
Inside the loop you can do something like the following to get text for all the buttons that are being created:
TextHolder firstOne = getList.get(i);
String text = firstOne.getText();
You will also need class with getters and setters method in order to convert DB elements into objects.Like in the above code getText() is our getter method which is getting elements from database and returning it here.
here text will be the text of the button.
So every-time users starts the application he will see all the buttons that he created when he ran the application before and newly added button will appear on the spot and also will be stored in the database for future retrieval.
Remember we are just storing text of the button and assigning it unique id which helps us to create the buttons.Hope this helps