<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rahul Rokade on Medium]]></title>
        <description><![CDATA[Stories by Rahul Rokade on Medium]]></description>
        <link>https://medium.com/@rahulbigv17?source=rss-dea83eacff68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Lbn4dtuig6Cj-Kaj</url>
            <title>Stories by Rahul Rokade on Medium</title>
            <link>https://medium.com/@rahulbigv17?source=rss-dea83eacff68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:49:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rahulbigv17/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kotlin Interview Questions And Answers]]></title>
            <link>https://medium.com/@rahulbigv17/kotlin-interview-questions-and-answers-f4e6baae27a6?source=rss-dea83eacff68------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4e6baae27a6</guid>
            <category><![CDATA[fresher-jobs]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <dc:creator><![CDATA[Rahul Rokade]]></dc:creator>
            <pubDate>Mon, 06 May 2024 06:57:28 GMT</pubDate>
            <atom:updated>2024-05-06T09:30:28.591Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*qcl18xHPkgs1S2tOBdOjtw.png" /></figure><p>Welcome to all Kotlin lovers. How are you? I hope you are very energetic and interview learned. <br>So Kotlin lovers, just share my minor story. WhenEver switches my job then my first work go to google search engin and just search and open multiple tab.😂🤣 That time hardly read only 1 hrs all tab. And after some time, the mind wandered and started thinking about dreams. So basically all learned your side available one cheat sheet. So all Kotlin lovers don’t waste your time and now your cheat sheet is ready. Daily 5 question read and proper understand.<br>If any mistake on my blog then please notify me. Thanks in advance. All Kotlin lovers, let’s get started basic to advance question share with you.</p><p><strong>What is Kotlin and how does it interoperate with Java?</strong></p><ul><li>Kotlin is a modern, statically typed language. Having been developed by JetBrains, it targets the JVM, among other platforms.</li></ul><p><strong>How does Kotlin work on Android?</strong></p><p>Just like Java, the Kotlin code is also compiled into the Java bytecode and is executed at runtime by the Java Virtual Machine.</p><p><strong>Why should we use Kotlin?</strong></p><p>Kotlin is statically typed programming language<br>Kotlin is interoperable with the Java programming language<br>Kotlin is concise<br>Kotlin is null-safe</p><p><strong>What is the difference between ‘const’ and ‘val’?</strong></p><p>The value of const variable is assigned during compile time, unlike the val variable, where it can be done at runtime. This means, const variables can never be assigned to a function or any class constructor, but only to a String or primitive.</p><p><strong>What is the difference between val and var in Kotlin?</strong></p><p>`val` is used to declare read-only (immutable) variables. Once assigned, the value of a `val` cannot be changed.</p><p>`var` is used to declare mutable variables. The value of a `var` can be reassigned multiple times.</p><p><strong>What are the basic data types in Kotlin?</strong></p><ul><li>Numbers: This includes types like Int (for integers), Double (for double-precision floating-point numbers), Float (for single-precision floating-point numbers), Long (for long integers), Short (for short integers), and Byte (for bytes).</li><li>Booleans: The Boolean type represents logical values, either true or false.</li><li>Characters: The Char type represents a single character.</li><li>Strings: The String type represents a sequence of characters.</li></ul><p><strong>Explain type inference in Kotlin.</strong></p><p>It’s important to note that once the type is inferred, it becomes fixed and cannot be changed. If you need a different type, you’ll have to explicitly declare it. For example: val name = “John”, val age = 25, val balance = 1000.0, val isActive = true.</p><p><strong>What are nullable types in Kotlin?</strong></p><p>This is in contrast to non-nullable types, which cannot hold null values by default. By using nullable types, the compiler enforces null safety and reduces the occurrence of null pointer exceptions.<br>val name: String? = null // Nullable String type<br>val age: Int? = 25 // Nullable Int type</p><p><strong>How do you handle nullability in Kotlin?</strong></p><p>you can handle nullability using several techniques:</p><p>1] Safe Calls: Use the safe call operator (?.) to safely access properties or call methods on a nullable object. If the object is null, the expression evaluates to null instead of throwing a null pointer exception.<br>val length: Int? = text?.length</p><p>2] Elvis Operator: The Elvis operator (?:) allows you to provide a default value when accessing a nullable object. If the object is null, the expression after the Elvis operator is returned instead.<br>val length: Int = text?.length ?: 0</p><p>3] Safe Casts: Use the safe cast operator (as?) to perform type casts on nullable objects. If the cast is unsuccessful, the result is null.<br>val name: String? = value as? String</p><p>4] Non-Null Assertion: When you are certain that a nullable variable is not null at a specific point, you can use the non-null assertion operator (!!) to bypass null safety checks. However, if the variable is actually null, a null pointer exception will occur.<br>val length: Int = text!!.length</p><p><strong>What is the Elvis operator in Kotlin?</strong></p><p>The Elvis operator (?:) is a shorthand notation in Kotlin that provides a default value when accessing a nullable object. <br>syntax: nullableObject ?: defaultValue<br>Example: <br>val name: String? = null <br>val length: Int = name?.length ?: 0</p><p><strong>What are Kotlin collections?</strong></p><p>Kotlin collections are used to store and manage groups of related data items. They provide a convenient way to work with multiple values as a single unit. Kotlin offers various collection types, such as lists, sets, and maps, each with its own characteristics and functionalities.</p><p>val numbers: List&lt;Int&gt; = listOf(1, 2, 3, 4, 5) // A list collection storing integers<br>val names: Set&lt;String&gt; = setOf(“Alice”, “Bob”, “Charlie”) // A set collection storing strings<br>val ages: Map&lt;String, Int&gt; = mapOf(“Alice” to 25, “Bob” to 30, “Charlie” to 35) // A map collection storing key-value pairs</p><p><strong>What is the difference between a list and an array in Kotlin?</strong></p><ul><li>Size: Lists can dynamically grow or shrink in size, whereas arrays have a fixed size that is determined at the time of creation.</li><li>Type Flexibility: Lists can store elements of different types using generics, allowing for heterogeneity. Arrays, on the other hand, are homogeneous and can store elements of a single type.</li><li>Modification: Lists provide convenient methods for adding, removing, or modifying elements. Arrays have fixed sizes, so adding or removing elements requires creating a new array or overwriting existing elements.</li><li>Performance: Arrays generally offer better performance for direct element access and modification, as they use contiguous memory locations. Lists, being dynamic, involve some level of overhead for resizing and maintaining their internal structure.</li></ul><p><strong>How do you create an empty list in Kotlin?</strong></p><p>In Kotlin, you can create an empty list using the listOf() function with no arguments. This creates a list with zero elements.<br>Example: <br>val emptyList: List&lt;Int&gt; = listOf() // Empty list of integers<br>It is initialized using the listOf() function without any elements.</p><p><strong>What are data classes in Kotlin? Explain with a proper example.</strong></p><p>The Data class is a simple class that holds data and provides typical functions. To declare a class as a data class, use the data keyword.</p><p>Syntax: data class className ( list_of_parameters)</p><p>The following functions are automatically derived by the compiler for the data classes:</p><ul><li>equals() — The equals() function returns true if two objects have the identical contents. It operates similarly to “==,” although for Float and Double values it works differently.</li><li>hashCode() — The hashCode() function returns the object’s hashcode value.</li><li>copy() — The copy() function is used to duplicate an object, changing only a few of its characteristics while leaving the rest unaltered.</li><li>toString() — This function returns a string containing all of the data class’s parameters.</li></ul><p>To ensure consistency, data classes must meet the following requirements:</p><ul><li>At least one parameter is required for the primary constructor.</li><li>val or var must be used for all primary constructor parameters.</li><li>Abstract, open, sealed, or inner data classes are not possible.</li><li>Only interfaces may be implemented by data classes.</li></ul><p><strong>What are the different types of constructors available in Kotlin? Explain them with proper examples.</strong></p><p>There are two types of Kotlin constructors:</p><p>1] Primary Constructor — This type of constructor is initialised in the class header and is provided after the class name. It is declared using the “constructor” keyword. Parameters are optional in this type of constructor. For example,</p><pre>class Person(val name: String, val age: Int) {<br>    fun greet() {<br>        println(&quot;Hello, my name is $name and I&#39;m $age years old.&quot;)<br>    }<br>}<br><br>fun main() {<br>    val person = Person(&quot;John&quot;, 25)<br>    person.greet() // Output: Hello, my name is John and I&#39;m 25 years old.<br>}</pre><p>If no annotations or access modifiers are provided, the constructor keyword can be omitted.</p><p>2] Secondary Constructor — Secondary constructors allow for the initialization of variables as well as the addition of logic to the class. They have the constructor keyword prefixed to them. For example,</p><pre>class Person {<br>        var name: String = &quot;&quot;<br>        var age: Int = 0<br><br>        constructor(name: String) {<br>            this.name = name<br>        }<br><br>        constructor(name: String, age: Int) {<br>            this.name = name<br>            this.age = age<br>        }<br>    }<br><br>    fun main() {<br>        val person1 = Person(&quot;John&quot;)<br>        val person2 = Person(&quot;Jane&quot;, 30)<br><br>        println(person1.name) // Output: John<br>        println(person1.age) // Output: 0<br><br>        println(person2.name) // Output: Jane<br>        println(person2.age) // Output: 30<br>    }<br><br>    class Sample constructor(val a: Int, val b: Int) {<br>        // code<br>    }</pre><p><strong>What is the difference between init and constructor in Kotlin?</strong></p><p>init is an initialization block that is executed when an instance of a class is created. It is used to initialize properties or perform other setup operations. The primary constructor and any secondary constructors are responsible for creating the instance, while the init block handles the initialization logic. The main difference is that the init block is always executed regardless of which constructor is used. Here&#39;s an example:</p><pre>class Person(name: String) {<br>    val greeting: String<br>    <br>    init {<br>        greeting = &quot;Hello, $name!&quot;<br>        println(&quot;Person initialized&quot;)<br>    }<br>}<br><br>fun main() {<br>    val person = Person(&quot;John&quot;) // Output: Person initialized<br>    <br>    println(person.greeting) // Output: Hello, John!<br>}</pre><p><strong>Explain the various methods to iterate over any data structure in Kotlin with examples.</strong></p><ul><li><strong>For Loop</strong> — The for loop is used to scan any data structure that supplies an iterator in this case. It is not used in the same way as the for loop in other programming languages such as Java or C.</li></ul><p><strong>Syntax</strong>: for(item in collection) { // code }</p><pre>// KOTLIN<br>fun main(args: Array&lt;String&gt;) {<br>   var numbersArray = arrayOf(1,2,3,4,5,6,7,8,9,10)<br> <br>   for (num in numbersArray){<br>       if(num % 2 == 0){<br>           print(&quot;$num &quot;)<br>       }<br>   }<br>}</pre><ul><li><strong>While Loop </strong>— It is made up of a code block and a condition to be checked for each iteration. First, the while condition is assessed, and if it is true, the code within the block is executed. Because the condition is verified every time before entering the block, it repeats until the condition turns false. The while loop can be thought of as a series of if statements that are repeated.</li></ul><p><strong>Syntax: </strong>while(condition) { // code }</p><pre>fun main(args: Array&lt;String&gt;) {<br>   var number = 1<br>   while(number &lt;= 5) {<br>       println(number)<br>       number++;<br>   }<br>}</pre><ul><li><strong>Do While Loop </strong>— The condition is assessed after all of the statements inside the block have been executed. If the do-while condition is true, the code block is re-executed. As long as the expression evaluates to true, the code block execution procedure is repeated. The loop ends if the expression becomes false, and control is passed to the sentence following the do-while loop. Because it verifies the condition after the block is executed, it’s also known as a post-test loop.</li></ul><p><strong>Syntax: </strong>do { // code }while(condition)</p><pre>fun main(args: Array&lt;String&gt;) {<br>   var number = 4<br>   var sum = 0<br> <br>   do {<br>       sum += number<br>       number--<br>   }while(number &gt; 0)<br>   println(&quot;Sum of first four natural numbers is $sum&quot;)<br>}</pre><p><strong>How can you concatenate two strings in Kotlin?</strong></p><p>Following are the different ways by which we can concatenate two strings in Kotlin:</p><p><strong><em>Using String Interpolation:-</em></strong> We use the technique of string interpolation to concatenate the two strings.</p><pre>val s1 = &quot;Rahul&quot;<br>val s2 = &quot;Rokade&quot;<br>val s3 = &quot;$s1 $s2&quot; // stores &quot;Rahul Rokade&quot;</pre><p><strong><em>Using the + or plus() operator:-</em></strong></p><pre>val s1 = &quot;Rahul&quot;<br>val s2 = &quot;Rokade&quot;<br>val s3 = &quot;$s1+$s2&quot; // stores &quot;RahulRokade&quot;<br>val s4 = s1.plus(s2) // stores &quot;RahulRokade&quot;</pre><p><strong><em>Using StringBuilder:-</em></strong></p><pre>val s1 = &quot;Rahul&quot;<br>val s2 = &quot;Rokade&quot;<br>val s3 =  StringBuilder()     <br>s3.append(s1).append(s2)<br>val s4 = s3.toString() // stores &quot;RahulRokade&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4e6baae27a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Upload Pdf File On Server]]></title>
            <link>https://medium.com/@rahulbigv17/how-to-upload-pdf-file-on-server-1ca2d28c3f0e?source=rss-dea83eacff68------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ca2d28c3f0e</guid>
            <category><![CDATA[file-upload]]></category>
            <category><![CDATA[upload]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[multipart-form-data]]></category>
            <dc:creator><![CDATA[Rahul Rokade]]></dc:creator>
            <pubDate>Wed, 21 Feb 2024 10:29:33 GMT</pubDate>
            <atom:updated>2024-02-21T10:29:33.217Z</atom:updated>
            <content:encoded><![CDATA[<p>My friend asked me the question “How to upload the file to a server using data?”. So just elaborate, step by step, all procedure. Then he was a happy after listing my story. If you are also a beginner and want to do work, then please follow me and read my story. If you are a new user of my blog, then please follow me, and please comment on how you feel after reading my story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*wYhyUTdT5zm92Gv5LawKhA.jpeg" /></figure><p>So now let’s get started with the step-by-step procedure.</p><p>So first upon understand “What is the way for upload data.” Any file uploading on server then used “Multi-part API”</p><p><strong>What is multi-part api?</strong></p><p>Multi-part requests combine one or more data sets into the body of a single request, separated by boundaries. A boundary is a unique string used to distinguish between these different data sets known as parts. Each part has its own section in the payload with internal HTTP headers.</p><p><strong>Why use multi-part/form-data?</strong></p><p>Multi-part/form-data allows you to submit binary data and multiple data types in a single request. For example, you can use these requests for file uploads and transferring a file with a Json object.</p><p>So first upon create service Retrofit Client.</p><p><strong>What is Retrofit Client?</strong></p><p>Retrofit is a REST client that can be used to make HTTP requests to RESTful APIs. It is a popular choice for Android development because it is easy to use, type-safe, and extensible.</p><p>Benefits of using Retrofit 🌟</p><ul><li>Type-safe: Retrofit uses annotations to generate code that maps JSON responses to Java objects. This makes it easy to work with the data returned from an API and helps to prevent errors. ✅</li><li>Easy to use: Retrofit provides a simple interface for making HTTP requests. You can create a request by specifying the URL, the method, and the parameters. Retrofit will then take care of sending the request and parsing the response. 🌐</li><li>Flexible: Retrofit can be used to make requests to any RESTful API. It supports a variety of HTTP methods, and it can also be used to make streaming requests. 🎛️</li><li>Extensible: Retrofit is extensible, so you can customize it to meet your specific needs. You can create your own custom converters to handle different types of data, and you can also create your own custom adapters to handle different types of APIs. 🧩</li></ul><p>How to use Retrofit 🛠️</p><p>To use Retrofit, you first need to create a Retrofit instance. You can do this by passing in the base URL of the API that you want to connect to.</p><p>Once you have created a Retrofit instance, you can create a request. You do this by creating a Call object.</p><p>The Call object represents a single HTTP request. You can use it to send the request, get the response, and handle errors.</p><p><strong>How to create client Service?</strong></p><p>Bellow all code used in one class file and assign name ApiClient</p><pre>private static Retrofit getRetrofit() {<br><br>    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();<br>    httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);<br><br>    OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(1, TimeUnit.MINUTES)<br>            .writeTimeout(1, TimeUnit.MINUTES)<br>            .readTimeout(1, TimeUnit.MINUTES)<br>            .addInterceptor(httpLoggingInterceptor).build();<br><br>    Gson gson = new GsonBuilder()<br>            .setLenient()<br>            .create();<br><br>    Retrofit retrofit = new Retrofit.Builder()<br>            .addConverterFactory(GsonConverterFactory.create(gson))<br>            .baseUrl(AppUtils.BASE_URL_NEW)<br>            .client(httpClient)<br>            .build();<br><br>    return retrofit;<br>}</pre><pre>public static ImageUploadService uploadService(){<br>    ImageUploadService imageUploadService = getRetrofit().create(ImageUploadService.class);<br>    return imageUploadService;<br>}</pre><p>Then create multi-part end point interface.</p><pre>public interface ImageUploadService {<br>    @Multipart<br>    @POST(&quot;SampleRequest/UploadAttachement&quot;)<br>    Call&lt;Void&gt; uploadImage(<br>            @Part MultipartBody.Part imagePart,<br>            @Part(&quot;SampleRequestID&quot;) RequestBody sampleRequestID,<br>            @Part(&quot;AttachedOn&quot;) RequestBody attachedOn);<br>}</pre><p><strong>What is a asynctask?</strong></p><p>Android AsyncTask is an abstract class provided by Android which gives us the liberty to perform heavy tasks in the background and keep the UI thread light thus making the application more responsive. Android application runs on a single thread when launched. Due to this single thread model tasks that take longer time to fetch the response can make the application non-responsive. To avoid this we use android AsyncTask to perform the heavy tasks in background on a dedicated thread and passing the results back to the UI thread. Hence use of AsyncTask in android application keeps the UI thread responsive at all times. The basic methods used in an android AsyncTask class are defined below :</p><ul><li><strong>doInBackground()</strong> : This method contains the code which needs to be executed in background. In this method we can send results multiple times to the UI thread by publishProgress() method. To notify that the background processing has been completed we just need to use the return statements</li><li><strong>onPreExecute()</strong> : This method contains the code which is executed before the background processing starts</li><li><strong>onPostExecute()</strong> : This method is called after doInBackground method completes processing. Result from doInBackground is passed to this method</li><li><strong>onProgressUpdate()</strong> : This method receives progress updates from doInBackground method, which is published via publishProgress method, and this method can use this progress update to update the UI thread</li></ul><p>The three generic types used in an android AsyncTask class are given below :</p><ul><li><strong>Params</strong> : The type of the parameters sent to the task upon execution</li><li><strong>Progress</strong> : The type of the progress units published during the background computation</li><li><strong>Result</strong> : The type of the result of the background computation</li></ul><p>The following code snippet must be present where to used in the class in order to launch an AsyncTask.</p><pre>MyTask myTask = new MyTask();<br>myTask.execute();</pre><p>So now Create file upload class file by using Asynctask.</p><pre>public class FileUploadTask extends AsyncTask&lt;Void, Void, Void&gt; {<br>    private static final String TAG = &quot;FileUploadTask&quot;;<br>    private File filePath;<br>    private String sampleRequestID;<br>    private String attachedOn;<br><br>    public FileUploadTask(File filePath, String sampleRequestID,String attachedOn) {<br>        this.filePath = filePath;<br>        this.sampleRequestID = sampleRequestID;<br>        this.attachedOn = attachedOn;<br>    }<br><br>    @Override<br>    protected Void doInBackground(Void... voids) {<br>        // Create a File instance from the file path<br>        File file = new File(String.valueOf(filePath));<br>        String sampleId = sampleRequestID;<br>        String attachOn = attachedOn;<br><br>        // Check if the file exists<br>        if (!file.exists() &amp;&amp; !sampleRequestID.isEmpty()) {<br>            Log.e(TAG, &quot;File not found: &quot; + filePath);<br>            Log.e(TAG, &quot;sampleRequestID: &quot; + sampleRequestID);<br>        }<br><br>        // Create a RequestBody instance from the file<br>        RequestBody fileRequestBody = RequestBody.create(MediaType.parse(&quot;multipart/form-data&quot;), file);<br><br>        // Create a MultipartBody.Part from the RequestBody<br>        MultipartBody.Part filePart = MultipartBody.Part.createFormData(&quot;file&quot;, file.getName(), fileRequestBody);<br><br>        // Create a description RequestBody<br>        RequestBody sampleRequestID = RequestBody.create(MediaType.parse(&quot;text/plain&quot;), sampleId);<br>        RequestBody attachedOn = RequestBody.create(MediaType.parse(&quot;text/plain&quot;), attachOn);<br><br>        // Get the FileUploadService instance<br>        ImageUploadService fileUploadService = ApiClient.uploadService();<br><br>        // Call the uploadFile method asynchronously<br>        Call&lt;Void&gt; call = fileUploadService.uploadImage(filePart, sampleRequestID,attachedOn);<br>        call.enqueue(new Callback&lt;Void&gt;() {<br>            @Override<br>            public void onResponse(Call&lt;Void&gt; call, Response&lt;Void&gt; response) {<br>                if (response.isSuccessful()) {<br>                    Log.i(TAG, &quot;File uploaded successfully&quot;);<br>                } else {<br>                    Log.e(TAG, &quot;Error uploading file. Server returned: &quot; + response.code());<br>                }<br>            }<br><br>            @Override<br>            public void onFailure(Call&lt;Void&gt; call, Throwable t) {<br>                Log.e(TAG, &quot;Error uploading file&quot;, t);<br>            }<br>        });<br><br>        return null;<br>    }<br>}</pre><p><strong>So now first getting the file from your device</strong></p><p>assign on global variable</p><pre>private static final int CHOOSE_FILE_TO_DEVICE = 1001;<br>Uri uri;<br>File file;</pre><pre>imgBrows.setOnClickListener(new View.OnClickListener() {<br>    @Override<br>    public void onClick(View v) {<br>        Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT);<br>        i.setType(&quot;*/*&quot;);<br>        startActivityForResult(i,CHOOSE_FILE_TO_DEVICE);<br><br>    }<br>});</pre><p>Below code, write here your appUtils file.</p><pre>public static File getFile(Context context, Uri uri) {<br>    File destinationFilename = new File(context.getFilesDir().getPath() + File.separatorChar + queryName(context, uri));<br><br>    try (InputStream ins = context.getContentResolver().openInputStream(uri)) {<br>        createFileFromStream(ins, destinationFilename);<br>    } catch (Exception ex) {<br>        Log.e(&quot;Save File&quot;, ex.getMessage());<br>        ex.printStackTrace();<br>    }<br>    return destinationFilename;<br>}</pre><p><strong>What is use of onActivityResult in android?</strong></p><p>When we start another activity from current activity to get the result for it, we call the method startActivityForResult(intent, RESPONSE_CODE);. It redirects to another activity like opens camera, gallery, etc. After taking image from gallery or camera then come back to current activity first method that calls is onActivityResult(int requestCode, int resultCode, Intent data). We get the result in this method like taken image from camera or gallery.</p><p><strong>Now getting file path from onActivityResult, please used bellow code.</strong></p><pre>@Override<br>public void onActivityResult(int requestCode, int resultCode, Intent data) {<br>    super.onActivityResult(requestCode, resultCode, data);<br>    if (requestCode == CHOOSE_FILE_TO_DEVICE &amp;&amp; resultCode == Activity.RESULT_OK) {<br>        uri = data.getData();<br>        file  = AppUtils.getFile(context, uri);<br>        text_show_path.setText(String.valueOf(file));<br>        Log.e(&quot;TAG&quot;, &quot;file : &quot;+file);<br>    }<br>}</pre><p><strong>Now excute multi-part api by using asynctask.</strong></p><pre>FileUploadTask fileUploadTask1 = new FileUploadTask(file,sampleId,&quot;Sample&quot;);<br>fileUploadTask1.execute();</pre><p>Now all step-by-step procedure you has been understand properly. I hope you are happy now reading this story.</p><p><strong>Thank You!!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ca2d28c3f0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to show the Grid layout view dynamically as well as add one line of code used, then convert to…]]></title>
            <link>https://medium.com/@rahulbigv17/how-to-show-the-grid-layout-view-dynamically-as-well-as-add-one-line-of-code-used-then-convert-to-e916a30be74a?source=rss-dea83eacff68------2</link>
            <guid isPermaLink="false">https://medium.com/p/e916a30be74a</guid>
            <category><![CDATA[horizontal-listview]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[grid-layout]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rahul Rokade]]></dc:creator>
            <pubDate>Fri, 09 Feb 2024 10:29:02 GMT</pubDate>
            <atom:updated>2024-02-09T10:30:08.897Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to show the Grid layout view dynamically as well as add one line of code used, then convert to it vertical recycling, is it possible?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Y17Ds-zawrG6gq3XwFmZCA.jpeg" /></figure><p>One friend asked me the question, then my answer was “YES”. So, guys, let’s get started and implement it as well. If you are a new member of my post, please follow me and subscribe to my page. And please comment here on how you feel after reading this story.</p><p><strong>So, first, upon understanding what the grid layout is?</strong></p><p>It is used to display elements and views as a rectangular grid. Gird layout and Grid view are two completely different terms and are used for other purposes. Grid view is a view, whereas Grid layout is a layout that can hold various views in it. I hope you understand properly.</p><p><strong>What is a recycler view?</strong></p><p>The RecyclerView is a ViewGroup that renders any adapter-based view in a similar way. It is supposed to be the successor of List view and <a href="http://developer.android.com/guide/topics/ui/layout/gridview.html">GridView</a>. One reason is that RecyclerView has a more extensible framework, especially since it provides the ability to implement both horizontal and vertical layouts. Use the RecyclerView widget when you have data collections whose elements change at runtime based on user action or network events.</p><p>If you want to use a RecyclerView, you will need to work with the following:</p><ul><li>RecyclerView.Adapter - To handle the data collection and bind it to the view</li><li>LayoutManager - Helps in positioning the items</li><li>ItemAnimator - Helps with animating the items for common operations such as Addition or Removal of item</li></ul><p><strong>What is a data set in a list or array of data?</strong></p><p>Collection types (sometimes called data structures) let you store multiple values, typical of the same data type, in an organized way. A collection might be an ordered list, a grouping of unique values, or a mapping of values of one data type to values of another. The ability to effectively use collections enables you to implement common features of Android apps, such as scrolling lists, as well as solve a variety of real-life programming problems that involve arbitrary amounts of data. Familiarity with object-oriented programming in java, including classes, interfaces, and generics.</p><p><strong>what is map collection in java?</strong></p><p>Map in Java is an interface available in java. util package and it stores the data in key and value pairs. It does not allow duplicate keys. The map interface in Java is often misunderstood as being a subtype of the Collections interface.</p><p><strong>So now perform practically.</strong></p><p>below provide here xml view and this side main role only recycle view.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:orientation=&quot;vertical&quot;<br>    tools:context=&quot;.activity.RentalActivity&quot;&gt;<br><br>    &lt;include layout=&quot;@layout/custom_toolbar&quot; /&gt;<br><br>    &lt;ScrollView<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;&gt;<br><br>            &lt;LinearLayout<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:padding=&quot;10dp&quot;<br>                android:layout_marginVertical=&quot;5dp&quot;<br>                android:layout_marginHorizontal=&quot;4dp&quot;<br>                android:background=&quot;@color/white&quot;<br>                android:orientation=&quot;vertical&quot;&gt;<br><br>                &lt;EditText<br>                    android:layout_width=&quot;match_parent&quot;<br>                    android:layout_height=&quot;match_parent&quot;<br>                    android:background=&quot;@drawable/coustome_editor_for_textbox&quot;<br>                    android:drawableLeft=&quot;@drawable/baseline_search_24&quot;<br>                    android:fontFamily=&quot;@font/ff_medium&quot;<br>                    android:drawablePadding=&quot;10dp&quot;<br>                    android:layout_marginBottom=&quot;10dp&quot;<br>                    android:hint=&quot;Search your query here&quot;<br>                    android:padding=&quot;10dp&quot; /&gt;<br><br>                &lt;TextView<br>                    android:layout_width=&quot;match_parent&quot;<br>                    android:layout_height=&quot;match_parent&quot;<br>                    android:background=&quot;@drawable/coustome_editor_for_textbox&quot;<br>                    android:drawableLeft=&quot;@drawable/baseline_chat_24&quot;<br>                    android:drawableRight=&quot;@drawable/baseline_arrow_forward_ios_24&quot;<br>                    android:fontFamily=&quot;@font/ff_medium&quot;<br>                    android:drawablePadding=&quot;10dp&quot;<br>                    android:padding=&quot;10dp&quot;<br>                    android:text=&quot;Chat with us&quot;<br>                    android:textSize=&quot;18dp&quot;<br>                    android:textStyle=&quot;bold&quot; /&gt;<br><br>                &lt;TextView<br>                    android:layout_width=&quot;wrap_content&quot;<br>                    android:layout_height=&quot;wrap_content&quot;<br>                    android:layout_marginTop=&quot;10dp&quot;<br>                    android:drawablePadding=&quot;10dp&quot;<br>                    android:fontFamily=&quot;@font/ff_medium&quot;<br>                    android:padding=&quot;10dp&quot;<br>                    android:text=&quot;How to use ?&quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textSize=&quot;18dp&quot;<br>                    android:textStyle=&quot;bold&quot; /&gt;<br><br>                &lt;LinearLayout<br>                    android:layout_width=&quot;match_parent&quot;<br>                    android:layout_height=&quot;match_parent&quot;<br>                    android:layout_marginTop=&quot;10dp&quot;<br>                    android:background=&quot;@color/white&quot;<br>                    android:gravity=&quot;center&quot;<br>                    android:orientation=&quot;horizontal&quot;&gt;<br><br>                    &lt;ProgressBar<br>                        android:layout_width=&quot;wrap_content&quot;<br>                        android:layout_height=&quot;wrap_content&quot;<br>                        android:visibility=&quot;gone&quot;<br>                        /&gt;<br><br>                    &lt;androidx.recyclerview.widget.RecyclerView<br>                        android:id=&quot;@+id/rec_HTU&quot;<br>                        android:layout_width=&quot;wrap_content&quot;<br>                        android:layout_height=&quot;wrap_content&quot;<br>                        android:fitsSystemWindows=&quot;true&quot;/&gt;<br><br><br>                &lt;/LinearLayout&gt;<br><br><br>                &lt;TextView<br>                    android:layout_width=&quot;wrap_content&quot;<br>                    android:layout_height=&quot;wrap_content&quot;<br>                    android:layout_marginTop=&quot;10dp&quot;<br>                    android:drawablePadding=&quot;10dp&quot;<br>                    android:padding=&quot;10dp&quot;<br>                    android:fontFamily=&quot;@font/ff_medium&quot;<br>                    android:text=&quot;All categories&quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textSize=&quot;18dp&quot;<br>                    android:textStyle=&quot;bold&quot; /&gt;<br><br>                &lt;androidx.recyclerview.widget.RecyclerView<br>                    android:id=&quot;@+id/rec_categorie&quot;<br>                    android:layout_width=&quot;match_parent&quot;<br>                    android:layout_height=&quot;match_parent&quot;<br>                    android:fitsSystemWindows=&quot;true&quot;/&gt;<br><br><br>            &lt;/LinearLayout&gt;<br><br>        &lt;/ScrollView&gt;<br><br>&lt;/LinearLayout&gt;<br><br></pre><p>This is java file</p><pre><br>public class HelpFragment extends Fragment {<br>    private static final String TAG = &quot;HelpFragment&quot;;<br>    private Context context;<br>    private View view;<br>    private TextView txtViewTicket;<br>    private HTUAdapter adapterHTU;<br>    private CategoriAdapter adapterCategorie;<br>    private RecyclerView recyclerHTU,recyclerCategorie;<br>    private LinearLayoutManager layoutManagerHTU;<br>    private GridLayoutManager layoutManagerCategorie;<br>    private ProgressBar loader;<br><br>    public HelpFragment() {<br><br>    }<br><br>    @Override<br>    public void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br><br>    }<br><br>    @Override<br>    public View onCreateView(LayoutInflater inflater, ViewGroup container,<br>                             Bundle savedInstanceState) {<br>        if (view == null) {<br>            view = inflater.inflate(R.layout.fragment_help, container, false);<br>            init();<br>        }<br>        return view;<br>    }<br>    private void init() {<br>        context = getActivity();<br>        txtViewTicket = view.findViewById(R.id.txt_view_ticket);<br>        recyclerHTU = view.findViewById(R.id.rec_HTU);<br>        recyclerCategorie = view.findViewById(R.id.rec_categorie);<br>        layoutManagerHTU = new LinearLayoutManager(context,RecyclerView.HORIZONTAL,true);<br>        layoutManagerHTU.setReverseLayout(true);<br>        layoutManagerHTU.setStackFromEnd(true);<br>        layoutManagerCategorie = new GridLayoutManager(context,2);<br>        onclick();<br>        setAdapter();<br>    }<br>    private void onclick(){<br>        txtViewTicket.setOnClickListener(new View.OnClickListener() {<br>            @Override<br>            public void onClick(View v) {<br>                startActivity(new Intent(context, WebViewActivity.class));<br>            }<br>        });<br>    }<br>    private void setAdapter(){<br>        adapterHTU = new HTUAdapter(context, DataSet.getHTUList(), new HTUAdapter.menuItemInterface() {<br>            @Override<br>            public void onItemClickListener(MenuItemModel model) {<br>                if (model != null) {<br>                    <br>                    if (model.getId() == 0) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    } else if (model.getId() == 1) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    } else if (model.getId() == 2) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    } else if (model.getId() == 3) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    }<br>                }<br>            }<br>        });<br>        recyclerHTU.setLayoutManager(layoutManagerHTU);<br>        recyclerHTU.setAdapter(adapterHTU);<br><br>        adapterCategorie = new CategoriAdapter(context, DataSet.getCategorieList(), new CategoriAdapter.menuItemInterface() {<br>            @Override<br>            public void onItemClickListener(MenuItemModel model) {<br>                if (model != null) {<br>                    Log.i(&quot;Palash&quot;, &quot;all data: &quot; + model.getTitle());<br>                    if (model.getId() == 0) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    } else if (model.getId() == 1) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    } else if (model.getId() == 2) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    } else if (model.getId() == 3) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    }else if (model.getId() == 4) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    }else if (model.getId() == 5) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    }else if (model.getId() == 6) {<br>                        context.startActivity(new Intent(context, SettingsActivity.class)<br>                                .putExtra(&quot;title&quot;, model.getTitle()));<br>                    }<br>                }<br>            }<br>        });<br>        recyclerCategorie.setLayoutManager(layoutManagerCategorie);<br>        recyclerCategorie.setAdapter(adapterCategorie);<br>    }<br>}</pre><p>Adapter java file</p><pre>public class CategoriAdapter extends RecyclerView.Adapter&lt;CategoriAdapter.ViewHolder&gt; {<br>    Context context;<br>    ArrayList&lt;MenuItemModel&gt; list;<br>    private menuItemInterface listener;<br><br>    public CategoriAdapter(Context context, ArrayList&lt;MenuItemModel&gt; list, menuItemInterface listener) {<br>        this.context = context;<br>        this.list = list;<br>        this.listener = listener;<br>    }<br>    public interface menuItemInterface{<br>        void onItemClickListener(MenuItemModel model);<br>    }<br><br>    @NonNull<br>    @Override<br>    public CategoriAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {<br>        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.list_view_categorie,parent,false));<br>    }<br><br>    @Override<br>    public void onBindViewHolder(@NonNull CategoriAdapter.ViewHolder holder, int position) {<br>        MenuItemModel model = list.get(position);<br>        if (model != null){<br>            holder.txtMenuTitle.setText(model.getTitle());<br>        }<br>        holder.itemView.setOnClickListener(new View.OnClickListener() {<br>            @Override<br>            public void onClick(View v) {<br>                listener.onItemClickListener(model);<br>            }<br>        });<br>    }<br><br>    @Override<br>    public int getItemCount() {<br>        return list.size();<br>    }<br><br>    public class ViewHolder extends RecyclerView.ViewHolder {<br>        TextView txtMenuTitle;<br><br>        public ViewHolder(@NonNull View itemView) {<br>            super(itemView);<br>            txtMenuTitle = itemView.findViewById(R.id.txt_title_categorie);<br>        }<br>    }<br>}</pre><p>Adapter item (file name : list view categories.xml)</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;wrap_content&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:layout_margin=&quot;8dp&quot;<br>    android:id=&quot;@+id/ll_menu_itme_categorie&quot;<br>    &gt;<br><br>    &lt;LinearLayout<br>        android:layout_width=&quot;150dp&quot;<br>        android:layout_height=&quot;60dp&quot;<br>        android:gravity=&quot;center_vertical&quot;<br>        android:padding=&quot;10dp&quot;<br>        android:background=&quot;@drawable/coustome_editor_for_textbox&quot;<br>        android:orientation=&quot;vertical&quot;&gt;<br><br><br>        &lt;TextView<br>            android:id=&quot;@+id/txt_title_categorie&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:fontFamily=&quot;@font/roboto_regular&quot;<br>            android:text=&quot;Ride And \nFare&quot; /&gt;<br><br>    &lt;/LinearLayout&gt;<br><br><br><br>&lt;/LinearLayout&gt;</pre><p>Menu Model</p><pre>public class MenuItemModel {<br>    int img;<br>    String title;<br>    String km;<br>    int id;<br><br>    public String getKm() {<br>        return km;<br>    }<br><br>    public void setKm(String km) {<br>        this.km = km;<br>    }<br><br>    public int getId() {<br>        return id;<br>    }<br><br>    public void setId(int id) {<br>        this.id = id;<br>    }<br><br>    public int getImg() {<br>        return img;<br>    }<br><br>    public void setImg(int img) {<br>        this.img = img;<br>    }<br><br>    public String getTitle() {<br>        return title;<br>    }<br><br>    public void setTitle(String title) {<br>        this.title = title;<br>    }<br>}</pre><p>Dataset used this utils directory</p><pre>public static ArrayList&lt;MenuItemModel&gt; getHTUList() {<br>    ArrayList&lt;MenuItemModel&gt; item = new ArrayList&lt;&gt;();<br>    MenuItemModel  itemModel = new MenuItemModel();<br>    itemModel.setId(0);<br>    itemModel.setImg(R.drawable.buy);<br>    itemModel.setTitle(&quot;Saver Packs&quot;);<br>    item.add(itemModel);<br><br>    itemModel = new MenuItemModel();<br>    itemModel.setId(1);<br>    itemModel.setImg(R.drawable.buy);<br>    itemModel.setTitle(&quot;Ride History&quot;);<br>    item.add(itemModel);<br><br>    itemModel = new MenuItemModel();<br>    itemModel.setId(2);<br>    itemModel.setImg(R.drawable.buy);<br>    itemModel.setTitle(&quot;Coins&quot;);<br>    item.add(itemModel);<br><br>    itemModel = new MenuItemModel();<br>    itemModel.setId(3);<br>    itemModel.setImg(R.drawable.buy);<br>    itemModel.setTitle(&quot;Buy Wynn&quot;);<br>    item.add(itemModel);<br><br>    return item;<br>}</pre><p><strong>Most important point used this layout manager</strong></p><p>horizontal view :</p><pre>layoutManagerHTU = new LinearLayoutManager(context,RecyclerView.HORIZONTAL,true);</pre><p>Grid view :</p><pre>layoutManagerCategorie = new GridLayoutManager(context,2);</pre><p><strong>I hope all points are understand properly. Thank you!!.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e916a30be74a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to open a new screen on button clicked, in Jetpack compose?]]></title>
            <link>https://medium.com/@rahulbigv17/how-to-open-a-new-screen-on-button-clicked-in-jetpack-compose-47c7b39e0e6?source=rss-dea83eacff68------2</link>
            <guid isPermaLink="false">https://medium.com/p/47c7b39e0e6</guid>
            <category><![CDATA[button]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[onclicklistener]]></category>
            <dc:creator><![CDATA[Rahul Rokade]]></dc:creator>
            <pubDate>Fri, 20 Oct 2023 08:23:31 GMT</pubDate>
            <atom:updated>2023-10-20T08:23:31.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*Sp0_DnyzoAkvnOrogU3KAA.png" /></figure><p>Good Morning all compose lover’s!!</p><p>Today’s learn, How to navigate a new screen on button clicked.</p><p>A button consists of text or an icon, or both, that communicates what action occurs when the user taps it.</p><p>Interface definition for a callback to be invoked when a view is clicked.</p><p>You want to call the first onClick from the second? Just extract the contents of your first onClick in a separate method and call that method from each onClick.</p><p>What is onClick () in android?</p><p>Specifies the action to perform when the user taps on a view. There can be multiple OnClick() nodes for a single &lt;Transition&gt; , with each OnClick() specifying a different target view and a different action to perform when the view is tapped.</p><p>What is onClick and OnClickListener in android?</p><p>These two methods have same purpose i.e to user can tap or click to perform an action. But way to implement it is a bit different. android:onClick was added in API level 4 to make it easier, more Javascript-web-like, and drive everything from the XML.</p><p>In Android, the <strong>OnClickListener()</strong> interface has an onClick(View v) method that is called when the view (component) is clicked. The code for a component’s functionality is written inside this method, and the listener is set using the <strong>setOnClickListener()</strong> method.</p><p><strong>But In Jetpack compose side totally different way</strong></p><p>The Button is a composable component — there are two functions which can be used to build this. The first takes the text (used to declare the text displayed on the button), onClick (used to handle click events on the button) and style (used to handle the style of the button) attributes.</p><pre>Button( onClick = { /*TODO*/ }, colors = ButtonDefaults.buttonColors(Color.Gray)){<br>                    Text(<br>                        text = &quot;SignUp&quot;,<br>                        style = TextStyle(fontSize = 14.sp)<br>                    )<br>                }</pre><p>Above code just created button in jetpack compose. Now perform to the action. So create first sealed class file. Now create “Routes” file name and provide class file name routes.</p><pre>sealed class Routes(val route: String) {<br>    object Login : Routes(&quot;Login&quot;)<br>    object Signup : Routes(&quot;Signup&quot;)<br>}</pre><p>Then create file for “Navigation” . This file perform to the action for file path navController.</p><pre>@Composable<br>fun Navigation(){<br>    val navController = rememberNavController()<br>    NavHost(navController = navController, startDestination = Routes.Splash.route) {<br><br>        composable(Routes.Login.route) {<br>            LoginScreen(navController = navController)<br>        }<br>        composable(Routes.Signup.route) {<br>            SignupScreen(navController = navController)<br>        }<br>    }<br>}</pre><p>And Now finally perform the action one screen to another screen.</p><pre>navController.navigate(Routes.Signup.route)</pre><pre>Button( onClick = { navController.navigate(Routes.Signup.route) }, colors = ButtonDefaults.buttonColors(Color.Gray)) {<br>                Text(<br>                    text = &quot;SignUp&quot;,<br>                    style = TextStyle(fontSize = 14.sp)<br>                )<br>            }</pre><p>Thank you for reading this post , if usable then please share with compose “Beginner student”. Please comment and follow me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47c7b39e0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Re-Usable Custom Toolbar In Jetpack Compose]]></title>
            <link>https://medium.com/@rahulbigv17/re-usable-custom-toolbar-in-jetpack-compose-d6955cd8e691?source=rss-dea83eacff68------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6955cd8e691</guid>
            <category><![CDATA[toolbar-android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[compose-ui]]></category>
            <category><![CDATA[custom-toolbar]]></category>
            <dc:creator><![CDATA[Rahul Rokade]]></dc:creator>
            <pubDate>Fri, 29 Sep 2023 07:47:41 GMT</pubDate>
            <atom:updated>2023-09-29T07:50:52.009Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*NMKq90n6V1zsgtDKdTnRTw.png" /></figure><p>What is the Jetpack Compose?<br>Jetpack Compose is a modern declarative UI Toolkit for Android. Compose makes it easier to write and maintain your app UI by providing a declarative API that allows you to render your app UI without imperatively mutating frontend views.</p><p>What is Android Toolbar?<br>Android Toolbar widget is generally found on the top of the screen. The application title, logo, navigation icon, and the menu bar is displayed inside the toolbar.</p><p>Now start, How can we developed custom toolbar in jetpack compose?</p><p>bellow code write here custom toolbar</p><pre>@SuppressLint(&quot;CoroutineCreationDuringComposition&quot;)<br>@OptIn(ExperimentalMaterial3Api::class)<br>@Composable<br>fun CustomToolbarScreen(navController: NavHostController, title: String, isBack: Boolean){<br>    val scaffoldState = rememberScaffoldState()<br>    val scope = rememberCoroutineScope()<br>    var isDrawerOpen = remember {<br>        mutableStateOf(false)<br>    }<br>    TopAppBar(<br>        colors = TopAppBarDefaults.smallTopAppBarColors(<br>            containerColor = MaterialTheme.colorScheme.primaryContainer,<br>            titleContentColor = MaterialTheme.colorScheme.primary,<br>        ),<br>        title = {<br>            Text(text = title,color = Color.Black,<br>                fontSize = 18.sp)<br>        },<br>        modifier = Modifier.background(colorPrimary),<br>        navigationIcon = {<br>            if (isBack){<br>                IconButton(onClick = {navController.navigateUp()}) {<br>                    Icon(Icons.Filled.ArrowBack, &quot;backIcon&quot;)<br>                }<br>            }else{<br>                IconButton(onClick = {<br>                    scope.launch {<br>                        scaffoldState.drawerState.open()<br>                        Log.i(&quot;Drawer&quot;, &quot;drawer Open: &quot;)<br>                    }<br>                }) {<br>                    Icon(Icons.Filled.Menu, &quot;backIcon&quot;)<br>                }<br>            }<br>        }<br>    )<br>}</pre><p>What is <a href="http://twitter.com/Preview">@Preview</a> annotation? And How to write <a href="http://twitter.com/Preview">@Preview</a> code in jetpack compose?</p><p>The <a href="http://twitter.com/Preview">@Preview</a> annotation tells Android Studio that this composable should be shown in the design view of this file.</p><pre>@Preview(showBackground = true)<br>@Composable<br>fun CustomToolbarPreview() {<br>    TaxyTheme {<br>        val navController = rememberNavController()<br>        CustomToolbarScreen(navController = navController, title = String(),true)<br>    }<br>}</pre><p>Now Custom Toolbar developed successfully, but right now how to use this toolbar for a multiple screen side.</p><p>Now used this simple screen like back button and title only.</p><pre>@OptIn(ExperimentalMaterial3Api::class)<br>@Composable<br>fun SignupScreen(navController: NavHostController){<br><br>    val state = rememberScrollState()<br>    LaunchedEffect(Unit) { state.animateScrollTo(100) }<br>    <br>    Scaffold(<br>        topBar = {<br>            CustomToolbarScreen(navController = navController, title = &quot;Signup&quot;, true)<br>        }<br>    )<br>    { innerPadding -&gt;<br>        Column (<br>            modifier = Modifier.padding(innerPadding).verticalScroll(state)<br>                .padding(20.dp),<br>            verticalArrangement = Arrangement.Center,<br>            horizontalAlignment = Alignment.CenterHorizontally<br>        ){<br>            //add your code<br>        }<br>    }<br>}</pre><p>Now used this Dashboard screen like Menu button and title only.</p><pre>@SuppressLint(&quot;UnusedMaterial3ScaffoldPaddingParameter&quot;)<br>@OptIn(ExperimentalMaterial3Api::class)<br>@Composable<br>fun DashboardScreen(navController: NavHostController) {<br>    Scaffold(<br>        topBar = { CustomToolbarScreen(navController = navController, title = &quot;Dashboard&quot;, false) }<br>    ) { innerPadding -&gt;<br>        Column(<br>            modifier = Modifier.padding(innerPadding),<br>            verticalArrangement = Arrangement.Center,<br>            horizontalAlignment = Alignment.CenterHorizontally<br>        ) {<br>            // add your code<br>        }<br>    }<br>}</pre><p>Now work successfully both screen</p><p>I hope this code is help for you, Please follow me and coomment on this post your review. This code avalable on github, If your requirment github code then I will share with you my github link. Thank you</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6955cd8e691" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>