Unable to set Image from Resource to Custom ImageView in Xamarin Android?












0















I am able to set image in Non-Custom ImageView but unable to set Image in Custom ImageView, app loads successfully but unable to see the Image, below is the code.



public class MainActivity : AppCompatActivity
{


public ImageTestView imageView;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.activity_main);
imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
imageView.SetImageResource(Resource.Mipmap.line_indent);

}
}

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageViewTestProject.ImageTestView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />


</RelativeLayout>

public class ImageTestView : ImageView
{
public ImageTestView(Context context,IAttributeSet attr) :
base(context,attr)
{

}
}









share|improve this question

























  • first thing you not doing anything in custom ImageTestView class.

    – Ashwini Bhat
    Nov 26 '18 at 5:27











  • If use your code , it will have a problem.There will have no constructors in your custom imageview.You can refer to G.hakim's answer.

    – Junior Jiang - MSFT
    Nov 26 '18 at 6:44











  • i used hakim's code but same problem

    – VINNUSAURUS
    Nov 26 '18 at 6:55











  • Why don't you try to move the image to drawable folder and then check if using it from that folder works?

    – G.hakim
    Nov 26 '18 at 10:33


















0















I am able to set image in Non-Custom ImageView but unable to set Image in Custom ImageView, app loads successfully but unable to see the Image, below is the code.



public class MainActivity : AppCompatActivity
{


public ImageTestView imageView;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.activity_main);
imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
imageView.SetImageResource(Resource.Mipmap.line_indent);

}
}

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageViewTestProject.ImageTestView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />


</RelativeLayout>

public class ImageTestView : ImageView
{
public ImageTestView(Context context,IAttributeSet attr) :
base(context,attr)
{

}
}









share|improve this question

























  • first thing you not doing anything in custom ImageTestView class.

    – Ashwini Bhat
    Nov 26 '18 at 5:27











  • If use your code , it will have a problem.There will have no constructors in your custom imageview.You can refer to G.hakim's answer.

    – Junior Jiang - MSFT
    Nov 26 '18 at 6:44











  • i used hakim's code but same problem

    – VINNUSAURUS
    Nov 26 '18 at 6:55











  • Why don't you try to move the image to drawable folder and then check if using it from that folder works?

    – G.hakim
    Nov 26 '18 at 10:33
















0












0








0








I am able to set image in Non-Custom ImageView but unable to set Image in Custom ImageView, app loads successfully but unable to see the Image, below is the code.



public class MainActivity : AppCompatActivity
{


public ImageTestView imageView;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.activity_main);
imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
imageView.SetImageResource(Resource.Mipmap.line_indent);

}
}

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageViewTestProject.ImageTestView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />


</RelativeLayout>

public class ImageTestView : ImageView
{
public ImageTestView(Context context,IAttributeSet attr) :
base(context,attr)
{

}
}









share|improve this question
















I am able to set image in Non-Custom ImageView but unable to set Image in Custom ImageView, app loads successfully but unable to see the Image, below is the code.



public class MainActivity : AppCompatActivity
{


public ImageTestView imageView;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.activity_main);
imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
imageView.SetImageResource(Resource.Mipmap.line_indent);

}
}

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageViewTestProject.ImageTestView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />


</RelativeLayout>

public class ImageTestView : ImageView
{
public ImageTestView(Context context,IAttributeSet attr) :
base(context,attr)
{

}
}






android android-activity view xamarin.android imageview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 7:04









G.hakim

3,5521831




3,5521831










asked Nov 25 '18 at 16:09









VINNUSAURUSVINNUSAURUS

1941414




1941414













  • first thing you not doing anything in custom ImageTestView class.

    – Ashwini Bhat
    Nov 26 '18 at 5:27











  • If use your code , it will have a problem.There will have no constructors in your custom imageview.You can refer to G.hakim's answer.

    – Junior Jiang - MSFT
    Nov 26 '18 at 6:44











  • i used hakim's code but same problem

    – VINNUSAURUS
    Nov 26 '18 at 6:55











  • Why don't you try to move the image to drawable folder and then check if using it from that folder works?

    – G.hakim
    Nov 26 '18 at 10:33





















  • first thing you not doing anything in custom ImageTestView class.

    – Ashwini Bhat
    Nov 26 '18 at 5:27











  • If use your code , it will have a problem.There will have no constructors in your custom imageview.You can refer to G.hakim's answer.

    – Junior Jiang - MSFT
    Nov 26 '18 at 6:44











  • i used hakim's code but same problem

    – VINNUSAURUS
    Nov 26 '18 at 6:55











  • Why don't you try to move the image to drawable folder and then check if using it from that folder works?

    – G.hakim
    Nov 26 '18 at 10:33



















first thing you not doing anything in custom ImageTestView class.

– Ashwini Bhat
Nov 26 '18 at 5:27





first thing you not doing anything in custom ImageTestView class.

– Ashwini Bhat
Nov 26 '18 at 5:27













If use your code , it will have a problem.There will have no constructors in your custom imageview.You can refer to G.hakim's answer.

– Junior Jiang - MSFT
Nov 26 '18 at 6:44





If use your code , it will have a problem.There will have no constructors in your custom imageview.You can refer to G.hakim's answer.

– Junior Jiang - MSFT
Nov 26 '18 at 6:44













i used hakim's code but same problem

– VINNUSAURUS
Nov 26 '18 at 6:55





i used hakim's code but same problem

– VINNUSAURUS
Nov 26 '18 at 6:55













Why don't you try to move the image to drawable folder and then check if using it from that folder works?

– G.hakim
Nov 26 '18 at 10:33







Why don't you try to move the image to drawable folder and then check if using it from that folder works?

– G.hakim
Nov 26 '18 at 10:33














2 Answers
2






active

oldest

votes


















1














Update



In the end, adding the image background through XML ended up solving the issue.



android:background="@mipmap/imagename"




Well I think the reason it's not working is that of the unavailable constructors and improper initialization



  public class ImageTestView : ImageView
{
Context mContext;
public ImageTestView (Context context) : base(context)
{
init(context, null);
}

public ImageTestView (Context context, Android.Util.IAttributeSet attrs) : base(context, attrs)
{
init(context, attrs);
}

public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
{
init(context, attrs);
}

public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
{
init(context, attrs);
}

private void init(Context ctx, Android.Util.IAttributeSet attrs)
{
mContext = ctx;
}
}


Then use this custom imageview in your app like:



<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageViewTestProject.ImageTestView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />
</RelativeLayout>


And then you can set the image resource to it like this:



    var imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
imageView?.SetImageResource(Resource.Mipmap.line_indent);


Revert in case this does not work or in case of queries






share|improve this answer


























  • No, it didn't work

    – VINNUSAURUS
    Nov 26 '18 at 6:54











  • Did you check if the image view was drawn on the screen or not? This could be an issue with your image and not the image container you know, try setting a background colour to it instead and comment this imageView?.SetImageResource(Resource.Mipmap.line_indent); and see if the ImageView is there

    – G.hakim
    Nov 26 '18 at 6:56













  • Yep, it is working with normal ImageView but not with custom imageview, but i think image is loaded but not visible.

    – VINNUSAURUS
    Nov 26 '18 at 6:58











  • i have set ImageView background color to red and color is showing.

    – VINNUSAURUS
    Nov 26 '18 at 7:00








  • 1





    So the problem is with setting the image and not with your ImageView I would suggest you try setting the background property from XML and see if that helps! android:background="@mipmap/imagename"

    – G.hakim
    Nov 26 '18 at 7:01





















0














1.First thing you not doing anything in custom ImageTestView class.



2.And setting the image Resource is wrong.either you have to taking from Drawable folder it should be.



imageView.SetImageResource(Resource.Drawable.line_indent);


I don't know in Xamarin Android.But if you know Android please refer this Example.it's bit similar to xamarin Android



http://www.java2s.com/Code/Android/UI/extendsImageView.htm






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469340%2funable-to-set-image-from-resource-to-custom-imageview-in-xamarin-android%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Update



    In the end, adding the image background through XML ended up solving the issue.



    android:background="@mipmap/imagename"




    Well I think the reason it's not working is that of the unavailable constructors and improper initialization



      public class ImageTestView : ImageView
    {
    Context mContext;
    public ImageTestView (Context context) : base(context)
    {
    init(context, null);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs) : base(context, attrs)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
    {
    init(context, attrs);
    }

    private void init(Context ctx, Android.Util.IAttributeSet attrs)
    {
    mContext = ctx;
    }
    }


    Then use this custom imageview in your app like:



    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageViewTestProject.ImageTestView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageView1" />
    </RelativeLayout>


    And then you can set the image resource to it like this:



        var imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
    imageView?.SetImageResource(Resource.Mipmap.line_indent);


    Revert in case this does not work or in case of queries






    share|improve this answer


























    • No, it didn't work

      – VINNUSAURUS
      Nov 26 '18 at 6:54











    • Did you check if the image view was drawn on the screen or not? This could be an issue with your image and not the image container you know, try setting a background colour to it instead and comment this imageView?.SetImageResource(Resource.Mipmap.line_indent); and see if the ImageView is there

      – G.hakim
      Nov 26 '18 at 6:56













    • Yep, it is working with normal ImageView but not with custom imageview, but i think image is loaded but not visible.

      – VINNUSAURUS
      Nov 26 '18 at 6:58











    • i have set ImageView background color to red and color is showing.

      – VINNUSAURUS
      Nov 26 '18 at 7:00








    • 1





      So the problem is with setting the image and not with your ImageView I would suggest you try setting the background property from XML and see if that helps! android:background="@mipmap/imagename"

      – G.hakim
      Nov 26 '18 at 7:01


















    1














    Update



    In the end, adding the image background through XML ended up solving the issue.



    android:background="@mipmap/imagename"




    Well I think the reason it's not working is that of the unavailable constructors and improper initialization



      public class ImageTestView : ImageView
    {
    Context mContext;
    public ImageTestView (Context context) : base(context)
    {
    init(context, null);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs) : base(context, attrs)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
    {
    init(context, attrs);
    }

    private void init(Context ctx, Android.Util.IAttributeSet attrs)
    {
    mContext = ctx;
    }
    }


    Then use this custom imageview in your app like:



    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageViewTestProject.ImageTestView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageView1" />
    </RelativeLayout>


    And then you can set the image resource to it like this:



        var imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
    imageView?.SetImageResource(Resource.Mipmap.line_indent);


    Revert in case this does not work or in case of queries






    share|improve this answer


























    • No, it didn't work

      – VINNUSAURUS
      Nov 26 '18 at 6:54











    • Did you check if the image view was drawn on the screen or not? This could be an issue with your image and not the image container you know, try setting a background colour to it instead and comment this imageView?.SetImageResource(Resource.Mipmap.line_indent); and see if the ImageView is there

      – G.hakim
      Nov 26 '18 at 6:56













    • Yep, it is working with normal ImageView but not with custom imageview, but i think image is loaded but not visible.

      – VINNUSAURUS
      Nov 26 '18 at 6:58











    • i have set ImageView background color to red and color is showing.

      – VINNUSAURUS
      Nov 26 '18 at 7:00








    • 1





      So the problem is with setting the image and not with your ImageView I would suggest you try setting the background property from XML and see if that helps! android:background="@mipmap/imagename"

      – G.hakim
      Nov 26 '18 at 7:01
















    1












    1








    1







    Update



    In the end, adding the image background through XML ended up solving the issue.



    android:background="@mipmap/imagename"




    Well I think the reason it's not working is that of the unavailable constructors and improper initialization



      public class ImageTestView : ImageView
    {
    Context mContext;
    public ImageTestView (Context context) : base(context)
    {
    init(context, null);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs) : base(context, attrs)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
    {
    init(context, attrs);
    }

    private void init(Context ctx, Android.Util.IAttributeSet attrs)
    {
    mContext = ctx;
    }
    }


    Then use this custom imageview in your app like:



    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageViewTestProject.ImageTestView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageView1" />
    </RelativeLayout>


    And then you can set the image resource to it like this:



        var imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
    imageView?.SetImageResource(Resource.Mipmap.line_indent);


    Revert in case this does not work or in case of queries






    share|improve this answer















    Update



    In the end, adding the image background through XML ended up solving the issue.



    android:background="@mipmap/imagename"




    Well I think the reason it's not working is that of the unavailable constructors and improper initialization



      public class ImageTestView : ImageView
    {
    Context mContext;
    public ImageTestView (Context context) : base(context)
    {
    init(context, null);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs) : base(context, attrs)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
    {
    init(context, attrs);
    }

    public ImageTestView (Context context, Android.Util.IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
    {
    init(context, attrs);
    }

    private void init(Context ctx, Android.Util.IAttributeSet attrs)
    {
    mContext = ctx;
    }
    }


    Then use this custom imageview in your app like:



    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageViewTestProject.ImageTestView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageView1" />
    </RelativeLayout>


    And then you can set the image resource to it like this:



        var imageView = FindViewById<ImageTestView>(Resource.Id.imageView1);
    imageView?.SetImageResource(Resource.Mipmap.line_indent);


    Revert in case this does not work or in case of queries







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 27 '18 at 6:30

























    answered Nov 26 '18 at 6:28









    G.hakimG.hakim

    3,5521831




    3,5521831













    • No, it didn't work

      – VINNUSAURUS
      Nov 26 '18 at 6:54











    • Did you check if the image view was drawn on the screen or not? This could be an issue with your image and not the image container you know, try setting a background colour to it instead and comment this imageView?.SetImageResource(Resource.Mipmap.line_indent); and see if the ImageView is there

      – G.hakim
      Nov 26 '18 at 6:56













    • Yep, it is working with normal ImageView but not with custom imageview, but i think image is loaded but not visible.

      – VINNUSAURUS
      Nov 26 '18 at 6:58











    • i have set ImageView background color to red and color is showing.

      – VINNUSAURUS
      Nov 26 '18 at 7:00








    • 1





      So the problem is with setting the image and not with your ImageView I would suggest you try setting the background property from XML and see if that helps! android:background="@mipmap/imagename"

      – G.hakim
      Nov 26 '18 at 7:01





















    • No, it didn't work

      – VINNUSAURUS
      Nov 26 '18 at 6:54











    • Did you check if the image view was drawn on the screen or not? This could be an issue with your image and not the image container you know, try setting a background colour to it instead and comment this imageView?.SetImageResource(Resource.Mipmap.line_indent); and see if the ImageView is there

      – G.hakim
      Nov 26 '18 at 6:56













    • Yep, it is working with normal ImageView but not with custom imageview, but i think image is loaded but not visible.

      – VINNUSAURUS
      Nov 26 '18 at 6:58











    • i have set ImageView background color to red and color is showing.

      – VINNUSAURUS
      Nov 26 '18 at 7:00








    • 1





      So the problem is with setting the image and not with your ImageView I would suggest you try setting the background property from XML and see if that helps! android:background="@mipmap/imagename"

      – G.hakim
      Nov 26 '18 at 7:01



















    No, it didn't work

    – VINNUSAURUS
    Nov 26 '18 at 6:54





    No, it didn't work

    – VINNUSAURUS
    Nov 26 '18 at 6:54













    Did you check if the image view was drawn on the screen or not? This could be an issue with your image and not the image container you know, try setting a background colour to it instead and comment this imageView?.SetImageResource(Resource.Mipmap.line_indent); and see if the ImageView is there

    – G.hakim
    Nov 26 '18 at 6:56







    Did you check if the image view was drawn on the screen or not? This could be an issue with your image and not the image container you know, try setting a background colour to it instead and comment this imageView?.SetImageResource(Resource.Mipmap.line_indent); and see if the ImageView is there

    – G.hakim
    Nov 26 '18 at 6:56















    Yep, it is working with normal ImageView but not with custom imageview, but i think image is loaded but not visible.

    – VINNUSAURUS
    Nov 26 '18 at 6:58





    Yep, it is working with normal ImageView but not with custom imageview, but i think image is loaded but not visible.

    – VINNUSAURUS
    Nov 26 '18 at 6:58













    i have set ImageView background color to red and color is showing.

    – VINNUSAURUS
    Nov 26 '18 at 7:00







    i have set ImageView background color to red and color is showing.

    – VINNUSAURUS
    Nov 26 '18 at 7:00






    1




    1





    So the problem is with setting the image and not with your ImageView I would suggest you try setting the background property from XML and see if that helps! android:background="@mipmap/imagename"

    – G.hakim
    Nov 26 '18 at 7:01







    So the problem is with setting the image and not with your ImageView I would suggest you try setting the background property from XML and see if that helps! android:background="@mipmap/imagename"

    – G.hakim
    Nov 26 '18 at 7:01















    0














    1.First thing you not doing anything in custom ImageTestView class.



    2.And setting the image Resource is wrong.either you have to taking from Drawable folder it should be.



    imageView.SetImageResource(Resource.Drawable.line_indent);


    I don't know in Xamarin Android.But if you know Android please refer this Example.it's bit similar to xamarin Android



    http://www.java2s.com/Code/Android/UI/extendsImageView.htm






    share|improve this answer




























      0














      1.First thing you not doing anything in custom ImageTestView class.



      2.And setting the image Resource is wrong.either you have to taking from Drawable folder it should be.



      imageView.SetImageResource(Resource.Drawable.line_indent);


      I don't know in Xamarin Android.But if you know Android please refer this Example.it's bit similar to xamarin Android



      http://www.java2s.com/Code/Android/UI/extendsImageView.htm






      share|improve this answer


























        0












        0








        0







        1.First thing you not doing anything in custom ImageTestView class.



        2.And setting the image Resource is wrong.either you have to taking from Drawable folder it should be.



        imageView.SetImageResource(Resource.Drawable.line_indent);


        I don't know in Xamarin Android.But if you know Android please refer this Example.it's bit similar to xamarin Android



        http://www.java2s.com/Code/Android/UI/extendsImageView.htm






        share|improve this answer













        1.First thing you not doing anything in custom ImageTestView class.



        2.And setting the image Resource is wrong.either you have to taking from Drawable folder it should be.



        imageView.SetImageResource(Resource.Drawable.line_indent);


        I don't know in Xamarin Android.But if you know Android please refer this Example.it's bit similar to xamarin Android



        http://www.java2s.com/Code/Android/UI/extendsImageView.htm







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 5:31









        Ashwini BhatAshwini Bhat

        3981316




        3981316






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469340%2funable-to-set-image-from-resource-to-custom-imageview-in-xamarin-android%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Futebolista

            Jornalista