I want to read data from the sqlite database in android studio and show them using TextView in a different activity say activity 2. So in first activity i will fill details and click submit button and on clicking the activity 2 will open and will show all the details that i inserted in activity 1 in textview.
this is a example.
String dataOne;
for(int i=0; i < mListData.size();i++){
dataOne = mListData.get(0).getName();
}
text_view.setText(dataOne);
This is the similar example what you are trying to achieve. below is the link
https://www.simplifiedcoding.net/how-to-fetch-data-from-sqlite-database-in-android/
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
My app users can create dynamic spinner and add items to it on click of button. Spinner is created using layout inflater.
Example :
User creates 2 spinner dynamically.
gives input for 1st spinner - male , female
gives input for 2nd spinner - apple , ball , cat.
Now I want get the data separate for each spinner and save it in firebase realtime database like.
(root)Dynamic->
spinner 1 ->
-Male
-female
spinner 2 ->
-apple
-ball
-cat
by using which method i can achieve this. i don't need the complete code just guide me which method to be used for it.
App Image : -
App screenshot
App screenshot
Lets say you have UserDefinedView class
class UserDefinedView {
String label;
String values[];
int id;
/*Other properties like viewType = [Spinner,EditText..]*/
}
Now create a list, where you can push user define views
ArrayList<UserDefinedView> userDefinedViews = new ArrayList<>();
UserDefinedView mUserObject = new UserDefinedView(/*label*/,/*Values*/,...);
userDefinedViews.push(mUserObject);
Now you can easily store array into firebase
thing is, if i click a button GETDATA - then a new activity starts new.java and i want it to display the contents of my database.
in this new.java i have strings name and id. and i have lined database and this class, such that name and id have the corresponding details that i want to display.
now the ques is, how to display them ?
if i have a
EditText ta;
ta=findViewBy(R.id.edittext1);
ta.setText(name);
should this work ?
it isnt working. also, i dont want user to change the contents and want to make this filed un-editable.
should i use
TextView tf;
ta=findViewBy(R.id.textview1);
tf.setText(name);
?
even this isnt happening.
what is the procedure for this ?
it is done by using append.
TextView ta;
ta=(TextEdit)findViewById(Ri.id.textView1);
String a=getData(1); // goto database, id is 1
ta.append(a);
i'm newbie to android program..I find some error in my final project tour travel app...i want to make listview that contain hotel list, then if listview was clicked will show detail hotel..ok..it works..
On detail hotel page there is a button "CEK KAMAR", it's used to show listview of room hotel based on ID hotel..i got stuck on this part..the listview has showed but all room class of all hotels..i can't filter the listview based on ID hotel..so..i really need help...thanks advance..
For more clear explanation, hereby i enclosed the screenshot app..
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