‫In this tutorial, we are going to allow the user to click on the question.
‫So the app takes him to the details activity and display the body of the question with the answers.
‫Hello again my friends.
‫So we have seen before how to fetch all the questions and trend questions, 20 questions from StackOverflow
‫and allow the dynamic implementation and direct direct fetching of these questions.
‫So.
‫As we see we have we have to open the stack overflow.
‫So our mission in this tutorial to fetch the question body.
‫So I will make a new classes like with body questions with body, and I will make edits for some codes
‫that will get the details of the questions.
‫So first of all, I will go to the Stack overflow.
‫Stack overflow API.
‫I will make another get response request and in the same way I need to get like this.
‫I will copy this and I will paste it, but I will make some edits.
‫You see guys on the the API that we have to edit the the ID of the question.
‫So let's go to the API of Stack Overflow and see what we are going to do.
‫So if I need to get the answers, I will use this.
‫If I need the questions, I will use this query and so on.
‫These are the.
‫The details about this.
‫Questions.
‫Okay, so.
‫We are going to work with this.
‫I will open it in a new tab.
‫And we see guys that if we need to test it, we are going to use this with the IDs query.
‫Okay.
‫Back to Android studio.
‫I will start making this by putting.
‫I can copy it.
‫I can copy it from here.
‫Copy.
‫And I will paste it here.
‫Okay.
‫This is good.
‫IDs order.
‫Okay.
‫Or we can make like a simple method that makes like this.
‫So you can use this or you can make this.
‫Questions.
‫Question ID, You can name it whatever you want, but because it is an query and site.
‫Equals stack overflow and get from the stack overflow filter.
‫Equal with body.
‫Okay.
‫We are getting the with body filter.
‫We make a call here and single.
‫I will make a.
‫A class about this response schema.
‫And the question details.
‫And I will make the path for this path because we are using the question ID and it is should it should
‫be the same as here.
‫So guys, it's very important.
‫It's case sensitive.
‫So I copy it and I paste it here.
‫And if you see the retrofit course, you can learn about this path query and whatever you want about
‫about the retrofit.
‫In this course.
‫Okay.
‫So we have finished making the stack overflow API.
‫Now I will go to single question response schema and I will edit it.
‫Oh sorry, I will create it first here and then I will edit the code.
‫Create a class single question response schema.
‫And this will work as.
‫Getting the question with the body.
‫Okay.
‫So first of all, I will make a serialized name called Item, which is the array that we have seen before.
‫The array of the response of objects that it is getting and results from the API of StackOverflow.
‫You remembered it, guys.
‫So you can go back to the previous previous lectures and stack overflow video and you learn more about
‫it.
‫Private final list and I will make a question with Buddy.
‫I will make also a new class called Question with Buddy.
‫Any question?
‫Okay.
‫I will create a class called like this.
‫Question with body.
‫I will edit it later, but till now I need to finish the single question response scheme.
‫I will create a new constructor here.
‫Having this and I will get.
‫The list using the getters.
‫Return questions dot get zero.
‫It's very simple, guys.
‫Okay.
‫Public.
‫Sorry.
‫It's a question.
‫I'm making a singleton with with body and get em questions.
‫Get questions?
‫Okay.
‫And here we go.
‫We have finished the single question schema.
‫Now let's go to the question with body and see how to solve it.
‫Question with body.
‫It is very.
‫It is very obvious that we need to fetch the question.
‫We need to fetch with the question with the body, the ID and the title of the question.
‫So if we go back to the Stack overflow, we see guys that if I put here the IDs.
‫IDs.
‫I put the 15 and it is mandatory.
‫You see, guys.
‫I will take.
‫This is the item.
‫And we need to pass also.
‫This is the wrong query that we have not used in the question.
‫I will go and copy this with body.
‫And you can go to them.
‫You can go to Postman and you can log in and to the to the account.
‫This is our friend.
‫Older friend.
‫Also, we have tested before on this site how to use this query and how to to get fetch APIs.
‫So the collaboration platform for API development and it is simple way and a simple tool that use to
‫to test the API.
‫But till now we are making everything working fine and not no need for using postman.
‫Okay.
‫And also if you want to learn more about postman, previous tutorials will learn you about it, will
‫teach you about it.
‫Okay.
‫I will need a private final.
‫And I need to the type of the data it is call, it is string and for the title and also I need to serialize
‫name also I'm going to fetch the question ID.
‫And the private final.
‫String and body.
‫Okay.
‫Or ID and ID.
‫And the last one is called serialized name.
‫It's the body.
‫Private final string.
‫And buddy.
‫Okay.
‫So in this this question with Buddy, I'm going to fetch the title, the question ID and the buddy and
‫stored them in three strings and display them into the details activity.
‫In order to do that, I will finish first using creating the constructor.
‫And I have finished the question.
‫With body.
‫The class.
‫And I'm going now to question details, activity.
‫Okay.
‫So I have created before in the first video, I think the questions with details.
‫Questions.
‫Questions, details, activity.
‫Okay.
‫And I have an annotation.
‫We will configure this activity later.
‫And it's now it's show time to make this a class function.
‫Okay, so what we have done is getting the ID of questions and display them and the title and displayed
‫them into the main activity, the list activity.
‫And what we have do in this video, what we have did in this video is making and allowing the user to
‫click on the question and display a go the retrofit, go and get the response of this ID of the question
‫whether body of the question, and we are going to display it into the questions, details, activity
‫that will open to the user and display the body of the question.
‫For that I will implement callback.
‫I, I am mandatory making these videos like very detailed because I, I know that if you, if you miss
‫something or you didn't understand anything or you didn't understand one topic in the video, it may
‫be unclear for the rest of tutorials for.
‫So I, I make it very obvious as I can do so.
‫Extra questions id equal to extra.
‫Question ID?
‫Okay, this is capital.
‫And this.
‫Okay, guys.
‫So remember, this activity is for displaying the details of the class.
‫Now.
‫I will make.
‫Also.
‫Here, some private declared, some variables and widgets, Text view and text.
‫Question body and private stack.
‫Stack overflow API and called em.
‫Stack.
‫Overflow API.
‫I will import the text view and here I need to create a private string and question ID.
‫Okay, so it's all clear now.
‫I'm going to initialize this oncreate.
‫No.
‫Question.
‫M question ID or.
‫Sorry, buddy.
‫Text, buddy.
‫That question, buddy.
‫Equal find view by ID or.id dot text.
‫Buddy.
‫I will make a layout for this activity.
‫I will click on the activity questions.
‫Details.
‫I will go to the source code now.
‫I will drag and drop.
‫A text view here.
‫And put the margins for zero.
‫Zero zero and adding the constraints for it.
‫And it is this form, this is the source code for this.
‫And I will name it as.
‫Text underscore question body.
‫Okay.
‫So text.
‫Question.
‫What?
‫Okay, so in this way we have initialized the text I need to make now the retrofit calls.
‫So retrofit retrofit equals new retrofit builder.
‫Retrofit builder base URL.
‫I will get them from the constant constants base URL.
‫And convert and we are going to use our friend Json converter.
‫Json converter factory dot create.
‫And again build.
‫So in this way we are making the retrofit Em Stack Overflow.
‫Stack Overflow API Equal.
‫Retrofit dot Create Stack Overflow.
‫API dot class.
‫Okay.
‫M Question ID or question id.
‫M Question id equal to get intent.
‫Don't get extras.
‫Get string are going to get the string.
‫From the past.
‫Extra question ID?
‫Okay.
‫So what we have done, we are passing from the list activity, the main activity, the ID of and the
‫extras for the question and passing them into the question details activity that we are going to allow
‫retrofit to make the calls.
‫Okay.
‫I will make public static void.
‫Start here.
‫And get the context.
‫Context.
‫I will pass the context importing the class and string question.
‫Question ID.
‫This method takes the context and a get, and that's the question ID and pass them to an intent.
‫I equal new intent, context and question details.
‫Activity.
‫That class.
‫Okay, so this is the method that we need to.
‫To create in this class and this activity.
‫So intent.
‫This is the intent.
‫I put extra dot.
‫Extra.
‫Extra
‫question ID and it is question ID.
‫Context Dot start activity.
‫Hi.
‫Okay.
‫I will cut this.
‫Method.
‫The above here, and we will continue making our class.
‫And activity.
‫So.
‫We have to implement the the two methods, the on response and on failure.
‫But first I need to override the on start method M call or call.
‫What is the name of the retrofit that we have to make?
‫It is called.
‫Should be cool.
‫Okay.
‫I have missed it.
‫Private call, and I need to get single.
‫Question response, schema and call.
‫Okay.
‫M call now.
‫Here.
‫M equal to m stac.
‫Or stack overflow API question details and I will pass the question ID.
‫So in this way I'm going to call the retrofit and Inc inc the callback passing this.
‫Okay.
‫Another, another way.
‫I need to.
‫Another method I need to.
‫It is to override is on stop if if the call and remember guys always stop the calls if they are equal
‫to null.
‫If there is no connections, I'm call or if it is.
‫Equal to now
‫get and go back to cancel.
‫Okay.
‫Now, one last thing I need to make is to configure the callback here.
‫Okay, so the callback.
‫I need to implement the methods so I click on.
‫Cluster import.
‫It is.
‫This and implement the methods on response and on Create.
‫Okay.
‫On response and on create.
‫These are the two methods that we will work.
‫Finally.
‫So single question response, schema, question schema.
‫And if the response is successful.
‫I can put them from.
‫Okay.
‫We have written them before, but it is good to write them again.
‫Question Response Schema
‫Equal.
‫Equal response.
‫The body.
‫And that it is not equal to does not equal to null.
‫Okay, so if.
‫There's here.
‫The question.
‫I need to put one here.
‫String question body.
‫Equal to question response schema dot get questions dot get body.
‫Get questions.
‫Get.
‫Buddy.
‫Okay.
‫I will configure it later.
‫But till now android android dot o s dot build dot version.
‫Virgin.
‫Dot.
‫As the k integer above or equal to.
‫Android.
‫N.
‫Do you need to make the the HTML and remove them from the HTML?
‫So android os dot build again.
‫I need to compare it with android n dot version.
‫Codes dot n.
‫Go and make em.
‫Text of a text by a question.
‫Body dot Set text.
‫To edgehtml from HTML dot body dot HTML or xhtml dot from HTML mode.
‫Mode legacy.
‫Legacy, not mode compact.
‫We are removing because we are getting the response from Jason and maybe sometimes it's form of xHTML
‫and some XML files and this will refine and make the code more more pretty fire and more more pretty
‫by making this text question dot set text to HTML dot from HTML question.
‫But okay.
‫Else I will call on failure.
‫So else go and call on failure.
‫Okay.
‫And I will pass the call and I will pass the null.
‫Again, I need to make the Onfailure fragment manager.
‫A fragment manager equal to get support Fragment.
‫Fragment manager.
‫And the fragment manager dot begin transaction.
‫Begin transaction dot add server error dialog fragment dot new instance and now.
‫And.
‫Commet.
‫Dell'est.
‫This is the finished commet.
‫Commit allowing state loss.
‫Okay.
‫So everything will should work fine.
‫I see that I have an error here in the question.
‫Body.
‫Questions.
‫Responses.
‫Schema questions.
‫I will go the questions response schema.
‫Okay.
‫I think I have written some wrong codes here, some maybe sometimes confusing between the single question
‫response schema and the question response schema.
‫Okay.
‫So we have we are getting the the Json response as an array and it's the name of this array.
‫It's called items and going here to the singles, to the constructor.
‫And I don't need a list, I need a question with body only.
‫So I need because I'm passing only one item.
‫So I'm questions equal to collection.
‫Thought.
‫Single.
‫Single list.
‫Singleton list.
‫Passing the question.
‫Okay.
‫Hear that question
‫again.
‫I hear I have with body and it is now good.
‫I'm going back.
‫I get, but get the questions.
‫Get, buddy.
‫I need also to configure the questions here.
‫Get questions and get the buddy.
‫Also, let's go to the question with body.
‫And here I need to.
‫Add that getters getters for body the title and the ID.
‫Now.
‫Everything should work fine.
‫Get.
‫Embody.
‫Okay, now let's make a clean project and then try to run our application.
‫Just one thing before we have missed to add the.
‫The click listener actions.
‫Okay.
‫I will restart the app and let's go to the main activity, the list activity.
‫And here I need to remove the annotation, the comment.
‫And in this way it will work.
‫So again, I will run the application.
‫Applying changes.
‫And let's see.
‫I will click on the first item.
‫And here we go.
‫We have the text.
‫But.
‫And it is updated with the question.
‫So how to implement server observer pattern?
‫Let's see.
‫Okay.
‫And this is the question.
‫I will remove the text view.
‫Well, it is ugly.
‫I will name it.
‫Loading, text loading question, buddy.
‫Okay.
‫So let's try again.
‫And see.
‫Okay, let's select.
‫Capturing from multiple threads.
‫Open CV loading question, buddy.
‫And here we go.
‫This is the question, buddy.
‫So, guys, I hope you benefit from our tutorial.
‫We have finished the basic StackOverflow API app and that we will work on dependency injection and make
‫this app clean architecture.
‫So starting from the next video we start, we are going to make dependency injection and we will make
‫clean architecture.
‫So keep us making new tutorials or just rate us five stars on Udemy and subscribe to our YouTube channel.
‫See you in next videos.