Hi Guy’s Welcome to Proto Coders Point. In this android studio article will learn to how to convert java file to kotlin & some developer are facing some error while converting java to kotlin let’s fix it.
How to Convert Android jave code to kotlin
Time needed: 1 minute
Step 1
Select the java file that you want to convert
Step 2
In Android Studio menubar goto Code
Step 3
In code menu you will see a option “convert java file to kotlin file”, Click on it and your file will get converted automatically to .kt.
Android Studio Convert Java to Kotlin not working
I was just trying to convert my old android project which is in JAVA language to kotlin but encounter and error:
Build was configured to prefer settings repositories over project repositories but repository ‘MavenRepo’ was added by build file ‘app\build.gradle.
Then after lot’s of research and solution by developer on stackoverflow I finally found out the 100% working solution on Android Convert Java File to Kotlin Not working.
Hi Guys, Welcome to Proto Coders Point, In this Android Tutorial will learn how to copy a text programmatically into clipboard in android apps, Source Code below for both JAVA & KOTLIN developer.
Copy text to clipboard android programmatically
Below is complete source code to learn how to copy and paste on android programmatically (copy to clipboard android).
Basically, android clipboard manager is a interface to a clipboard services, use to easily save any text in clipData and to retrieve the text global in a mobile device.
The ClipboardManager is best, easily to use & understand: it contains some methods by which we can get & set the current clipboard data as primary copyed text.
Snippet Code For Java
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("label","The Text you want to copy in clipboard"); // Example: In real-time, Value from textview
clipboardManager.setPrimaryClip(clipData);
Snippet Code For Kotlin
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("label", txtview2cpy!!.text.toString())
clipboardManager.setPrimaryClip(clipData)
Clipboard manager android example with source code
Note: Below code is just an example, Use it to implement in real-time projects. ALL THE BEST.
Code Explaination in brief
Below I have 2 views (TextView & a Button). In TextView I have a text that I want to copy into android clipboard as PainText data, Then I have a button that simply copy the text from textview and get saved into clipdata (so that I can paste the copied text somewhere else easily).
Hi Guy’s Welcome to Proto Coders Point, In this Flutter dart article let’s learn how to validate a String Variable to check if the given String is empty or null.
Suppose, You are building an application where you ask user to enter some data & you don’t accept empty or null value.
At situation, we need to check if string is empty or null, Let’s Start:
Function to check of String is null or empty
Will create a function/method that will validate our string, Let’s name the function as stringValidator()
Hi Guys, Welcome to Proto Coders Point. In this flutter tutorial article will learn how to build listview with list of items in it, & onTap selected item will be displayed on next screen, In the mean while will learn how to pass selected data to next screen.
Flutter Listview OnTap Pass Selected Data to Next Page, with Next & Previous Button to switch items
Video Tutorial
Flutter Listview onTap pass data to next page & has next & previous button on page 2
So when user select an item from listview.builder, the selected item data is been passed to page 2 and data is been shown, but if the user wants to read next data item from the list then he has to go back to first page and select the next data item from listview, which is not fully userfriendly.
In this flutter tutorial article, will add new Feature i.e:
In page no 2, There will be 2 buttons (previous & next) by using which user can change or swap the item from listview by being in page 2 itself. There is not need for user to go back to page 1 to select next item from list.
Complete Source Code – Flutter Listview With Example
Step by Step
We need to create 2 Screen and a dataModel class
(Screen 1) main.dart: Will generate list of data and show in flutter listview.
(Screen 2) FruitDetail.dart: User selected item data will be shown here.
(DataModel) FruitDataModel: Holds Information or a data.
Create above 3 files, for better understanding refer my file project structure.
1. FruitDataModel.dart
A Data Model are class of entities that holds information or a data.
In our app, DataModel has 3 String datatype.
Eg: Name of Fruit. ImageUrl of Fruit. Description of Fruit.
CodeDataModel
class FruitDataModel{
final String name,ImageUrl,desc;
FruitDataModel(this.name, this.ImageUrl, this.desc);
}
DataModel will have a constructor to assign the value to variables strings.
2. FruitDetail.dart
In fruitDetail page, will display details of selected Item from the listview of flutter app.
FruitDetail has a constructor that accept 2 parameter from page 1(main.dart) while navigating.
Index of user selected item from list.
FruitDataModel The whole List of data.
It also has 2 buttons (Prev & Next) by which user can change contents of the page.
Hi Guys Welcome to Proto Coders Point. This article is on a quick solution to an error i.e "There are multiple heroes that share the same tag within a subtree" in flutter.
Long time ago while developing a flutter application for my client, I encountered an error been show when I used 2 or more FloatingActionButton on same page.
I/flutter (21786): In this case, multiple heroes had the following tag: default FloatingActionButton tag
Here the Error simple means that, If you are adding more then 1 FloatingActionButton widget in one page or screen, then you have to add heroTag to each FloatingActionButton widget.
My FloatingActionButton after adding heroTag
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
FloatingActionButton(
heroTag: "f1", // add a unique tag
onPressed: (){},
child:Icon(Icons.arrow_back_ios) ,
),
FloatingActionButton(
heroTag: "f2", // add a unique tag
onPressed: (){},
child:Icon(Icons.arrow_forward_ios),
),
],
),
Just by adding unique heroTag to FloatingActionButton the error will get solved 100%.
Hi Guys, Welcome to Proto Coders Point. In this Android Article will learn how to implement taking screenshot in your android application, Now every mobile device has a inbuilt feature by which users can easily capture screenshots.
Suppose you want to implement programmatically take screenshot in your android application as a special feature of your app then this article will help you.
Take Screenshot in android programmatically
Final Output of below code implementation
ImplementationStep by Step
Step 1: Open or Create new Android Project
Create a new android project in android studio or open any existing android project where you want to implement screenshot taking feature.
Step 2: Add storage read & Write permission
As we are going to take screenshot and store the capture image in storage, we need to add permission to access storage, Therefore open AndroidManifest.xml file
Android > app > Manifest > AndroidManifest.xml
Within Manifest tag add below 3 storage permission