How to Get Resource Name from Resource Id

How to get Resource Name from Resource id

In your Activity, try these:

  1. to get string like radio1:

    getResources().getResourceEntryName(int resid);
  2. 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
    Sample Image

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]
}

Sample Image

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]
}

Sample Image

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



Leave a reply



Submit