How to get Resource Name from Resource id
In your Activity, try these:
to get string like
radio1
:getResources().getResourceEntryName(int resid);
to get string like
com.sample.app:id/radio1
:getResources().getResourceName(int resid);
In Kotlin Now :
val name = v.context.resources.getResourceEntryName(v.id)
How to get a resource id with a known resource name?
It will be something like:
R.drawable.resourcename
Make sure you don't have the Android.R
namespace imported as it can confuse Eclipse (if that's what you're using).
If that doesn't work, you can always use a context's getResources
method ...
Drawable resImg = this.context.getResources().getDrawable(R.drawable.resource);
Where this.context
is intialised as an Activity
, Service
or any other Context
subclass.
Update:
If it's the name you want, the Resources
class (returned by getResources()
) has a getResourceName(int)
method, and a getResourceTypeName(int)
?
Update 2:
The Resources
class has this method:
public int getIdentifier (String name, String defType, String defPackage)
Which returns the integer of the specified resource name, type & package.
How to get resource name from resource Id in azure cli
- We got the below error when we tried to get NetworkInterface Name with Resource ID
To get the NIC details of particular VM, use the below command
$virtualmachine = Get-AzVM -VMName "VMName"
$virtualmachine.NetworkProfile
$nic = $virtualmachine.NetworkProfile.NetworkInterfaces
foreach($nics in $nic) {
($nics.Id -split '/')[-1]
}
To get the NIC details of all the VM's in a ResourceGroup ,use
$virtualmachine= Get-AzVM -ResourceGroupName "YourRGName"
$virtualmachine.NetworkProfile
$nic = $virtualmachine.NetworkProfile.NetworkInterfaces
foreach($nics in $nic) {
($nics.Id -split '/')[-1]
}
References taken from :
Azure VM NIC name using PowerShell
Network interface object for an Azure VM
How can I get drawable resource by string?
You can use LocalContext
to get current context, and then use same methods as you used in view based Android:
val context = LocalContext.current
val drawableId = remember(name) {
context.resources.getIdentifier(
name,
"drawable",
context.packageName
)
}
Image(
painterResource(id = drawableId),
contentDescription = "..."
)
Related Topics
Android App Out of Memory Issues - Tried Everything and Still at a Loss
Communication Between Android Java and Phonegap JavaScript
Android - Package Name Convention
Android Static Object Lifecycle
Android Studio - How to Increase Allocated Heap Size
Where Are Shared Preferences Stored
How to Handle a Lost Keystore Password in Android
Default Firebaseapp Is Not Initialized
How to Create a Custom Navigation Drawer in Android
How to Determine Android Physical Screen Height in Cm or Inches
How to Control the Width and Height of the Default Alert Dialog in Android
Simplecursortreeadapter and Cursorloader for Expandablelistview
How to Set Mobile System Time and Date in Android
Activity Ondestroy Never Called
How to Display the Current Value of an Android Preference in the Preference Summary
Recyclerview Expand/Collapse Items
Difference and Uses of Oncreate(), Oncreateview() and Onactivitycreated() in Fragments