xamarin android gridview mess up after scrolling












0














i'm new to Xamarin android(which is very similar to android). I created a Gridview having images(from google images) with title the images stored in local db as a blob. when i scrolling it down its totally messing up. Here my code



activity_main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<android.support.design.widget.TabLayout
android:id="@+id/tablayout_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#A5BFB6"
android:layout_alignParentTop="true"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp" />
</LinearLayout>


album1_fragment.xml



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:id="@+id/album_frame_layout">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/albumsGridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</FrameLayout>


album_adapter.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">

<ImageView
android:id="@+id/albumImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:layout_gravity="center" />

<TextView
android:id="@+id/albumName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="trebuchet"
android:textSize="15sp"
android:lines="2"
android:layout_marginTop="5px"
android:textStyle="bold" />

</LinearLayout>


AlbumAdapter.cs



public class AlbumAdapter : BaseAdapter<Albums>
{
public List<Albums> albumData;
public List<Albums> _items;
Activity context;


public AlbumAdapter(Activity context, IEnumerable<Albums> albumData)
{
_items = albumData.OrderBy(s => s.AlbumName).ToList();

this.context = context;
}


public override Albums this[int position]
{
get
{
return _items[position];
}
}

public override int Count
{
get
{
return _items.Count;
}
}


public override long GetItemId(int position)
{
return position;
}

public override View GetView(int position, View convertView, ViewGroup parent)
{
var view = convertView;
var albums = _items[position];
AlbumHolder holder;

if (view == null)
{

view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.album_gridview_adapter, parent, false);

var albumImage = view.FindViewById<ImageView>(Resource.Id.albumImageView);
var albumName = view.FindViewById<TextView>(Resource.Id.albumName);
albumName.SetTextColor(Color.Black);


view.Tag = new AlbumHolder()
{
AlbumCover = albumImage,
AlbumName = albumName
};

holder = (AlbumHolder)view.Tag;
holder.AlbumCover.SetImageBitmap(ByteArrayToImageSourceConverter.ImageConverter(_items[position].AlbumCover));
holder.AlbumName.Text = _items[position].AlbumName;
}
else
{
holder = (AlbumHolder)view.Tag;
}

return view;
}

}


ByteArrayToImageSourceConverter : to convert byte data into bitmap



 public static class ByteArrayToImageSourceConverter
{

public static Bitmap ImageConverter(byte albumImage)
{
Bitmap bitmap = BitmapFactory.DecodeByteArray(albumImage, 0, albumImage.Length);

return bitmap;
}
}


here the output:
screen shot of my app



and how the above screen to convert like this:
screen shot of music player



Here the project source:https://github.com/udayoleti/XAMARIN



thanks in advance.










share|improve this question
























  • You are fetching instance of few controls incorrectly. var albumImage = view.. this should be holder.AlbumName=view.... If you are getting instances outside of holder than no meaning of using holder class. Even albumName.SetTextColor this should be holder.albumName.SetTextColor.
    – CGPA6.4
    Nov 23 at 9:28


















0














i'm new to Xamarin android(which is very similar to android). I created a Gridview having images(from google images) with title the images stored in local db as a blob. when i scrolling it down its totally messing up. Here my code



activity_main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<android.support.design.widget.TabLayout
android:id="@+id/tablayout_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#A5BFB6"
android:layout_alignParentTop="true"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp" />
</LinearLayout>


album1_fragment.xml



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:id="@+id/album_frame_layout">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/albumsGridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</FrameLayout>


album_adapter.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">

<ImageView
android:id="@+id/albumImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:layout_gravity="center" />

<TextView
android:id="@+id/albumName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="trebuchet"
android:textSize="15sp"
android:lines="2"
android:layout_marginTop="5px"
android:textStyle="bold" />

</LinearLayout>


AlbumAdapter.cs



public class AlbumAdapter : BaseAdapter<Albums>
{
public List<Albums> albumData;
public List<Albums> _items;
Activity context;


public AlbumAdapter(Activity context, IEnumerable<Albums> albumData)
{
_items = albumData.OrderBy(s => s.AlbumName).ToList();

this.context = context;
}


public override Albums this[int position]
{
get
{
return _items[position];
}
}

public override int Count
{
get
{
return _items.Count;
}
}


public override long GetItemId(int position)
{
return position;
}

public override View GetView(int position, View convertView, ViewGroup parent)
{
var view = convertView;
var albums = _items[position];
AlbumHolder holder;

if (view == null)
{

view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.album_gridview_adapter, parent, false);

var albumImage = view.FindViewById<ImageView>(Resource.Id.albumImageView);
var albumName = view.FindViewById<TextView>(Resource.Id.albumName);
albumName.SetTextColor(Color.Black);


view.Tag = new AlbumHolder()
{
AlbumCover = albumImage,
AlbumName = albumName
};

holder = (AlbumHolder)view.Tag;
holder.AlbumCover.SetImageBitmap(ByteArrayToImageSourceConverter.ImageConverter(_items[position].AlbumCover));
holder.AlbumName.Text = _items[position].AlbumName;
}
else
{
holder = (AlbumHolder)view.Tag;
}

return view;
}

}


ByteArrayToImageSourceConverter : to convert byte data into bitmap



 public static class ByteArrayToImageSourceConverter
{

public static Bitmap ImageConverter(byte albumImage)
{
Bitmap bitmap = BitmapFactory.DecodeByteArray(albumImage, 0, albumImage.Length);

return bitmap;
}
}


here the output:
screen shot of my app



and how the above screen to convert like this:
screen shot of music player



Here the project source:https://github.com/udayoleti/XAMARIN



thanks in advance.










share|improve this question
























  • You are fetching instance of few controls incorrectly. var albumImage = view.. this should be holder.AlbumName=view.... If you are getting instances outside of holder than no meaning of using holder class. Even albumName.SetTextColor this should be holder.albumName.SetTextColor.
    – CGPA6.4
    Nov 23 at 9:28
















0












0








0







i'm new to Xamarin android(which is very similar to android). I created a Gridview having images(from google images) with title the images stored in local db as a blob. when i scrolling it down its totally messing up. Here my code



activity_main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<android.support.design.widget.TabLayout
android:id="@+id/tablayout_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#A5BFB6"
android:layout_alignParentTop="true"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp" />
</LinearLayout>


album1_fragment.xml



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:id="@+id/album_frame_layout">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/albumsGridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</FrameLayout>


album_adapter.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">

<ImageView
android:id="@+id/albumImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:layout_gravity="center" />

<TextView
android:id="@+id/albumName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="trebuchet"
android:textSize="15sp"
android:lines="2"
android:layout_marginTop="5px"
android:textStyle="bold" />

</LinearLayout>


AlbumAdapter.cs



public class AlbumAdapter : BaseAdapter<Albums>
{
public List<Albums> albumData;
public List<Albums> _items;
Activity context;


public AlbumAdapter(Activity context, IEnumerable<Albums> albumData)
{
_items = albumData.OrderBy(s => s.AlbumName).ToList();

this.context = context;
}


public override Albums this[int position]
{
get
{
return _items[position];
}
}

public override int Count
{
get
{
return _items.Count;
}
}


public override long GetItemId(int position)
{
return position;
}

public override View GetView(int position, View convertView, ViewGroup parent)
{
var view = convertView;
var albums = _items[position];
AlbumHolder holder;

if (view == null)
{

view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.album_gridview_adapter, parent, false);

var albumImage = view.FindViewById<ImageView>(Resource.Id.albumImageView);
var albumName = view.FindViewById<TextView>(Resource.Id.albumName);
albumName.SetTextColor(Color.Black);


view.Tag = new AlbumHolder()
{
AlbumCover = albumImage,
AlbumName = albumName
};

holder = (AlbumHolder)view.Tag;
holder.AlbumCover.SetImageBitmap(ByteArrayToImageSourceConverter.ImageConverter(_items[position].AlbumCover));
holder.AlbumName.Text = _items[position].AlbumName;
}
else
{
holder = (AlbumHolder)view.Tag;
}

return view;
}

}


ByteArrayToImageSourceConverter : to convert byte data into bitmap



 public static class ByteArrayToImageSourceConverter
{

public static Bitmap ImageConverter(byte albumImage)
{
Bitmap bitmap = BitmapFactory.DecodeByteArray(albumImage, 0, albumImage.Length);

return bitmap;
}
}


here the output:
screen shot of my app



and how the above screen to convert like this:
screen shot of music player



Here the project source:https://github.com/udayoleti/XAMARIN



thanks in advance.










share|improve this question















i'm new to Xamarin android(which is very similar to android). I created a Gridview having images(from google images) with title the images stored in local db as a blob. when i scrolling it down its totally messing up. Here my code



activity_main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<android.support.design.widget.TabLayout
android:id="@+id/tablayout_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#A5BFB6"
android:layout_alignParentTop="true"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp" />
</LinearLayout>


album1_fragment.xml



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:id="@+id/album_frame_layout">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/albumsGridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</FrameLayout>


album_adapter.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">

<ImageView
android:id="@+id/albumImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:layout_gravity="center" />

<TextView
android:id="@+id/albumName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="trebuchet"
android:textSize="15sp"
android:lines="2"
android:layout_marginTop="5px"
android:textStyle="bold" />

</LinearLayout>


AlbumAdapter.cs



public class AlbumAdapter : BaseAdapter<Albums>
{
public List<Albums> albumData;
public List<Albums> _items;
Activity context;


public AlbumAdapter(Activity context, IEnumerable<Albums> albumData)
{
_items = albumData.OrderBy(s => s.AlbumName).ToList();

this.context = context;
}


public override Albums this[int position]
{
get
{
return _items[position];
}
}

public override int Count
{
get
{
return _items.Count;
}
}


public override long GetItemId(int position)
{
return position;
}

public override View GetView(int position, View convertView, ViewGroup parent)
{
var view = convertView;
var albums = _items[position];
AlbumHolder holder;

if (view == null)
{

view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.album_gridview_adapter, parent, false);

var albumImage = view.FindViewById<ImageView>(Resource.Id.albumImageView);
var albumName = view.FindViewById<TextView>(Resource.Id.albumName);
albumName.SetTextColor(Color.Black);


view.Tag = new AlbumHolder()
{
AlbumCover = albumImage,
AlbumName = albumName
};

holder = (AlbumHolder)view.Tag;
holder.AlbumCover.SetImageBitmap(ByteArrayToImageSourceConverter.ImageConverter(_items[position].AlbumCover));
holder.AlbumName.Text = _items[position].AlbumName;
}
else
{
holder = (AlbumHolder)view.Tag;
}

return view;
}

}


ByteArrayToImageSourceConverter : to convert byte data into bitmap



 public static class ByteArrayToImageSourceConverter
{

public static Bitmap ImageConverter(byte albumImage)
{
Bitmap bitmap = BitmapFactory.DecodeByteArray(albumImage, 0, albumImage.Length);

return bitmap;
}
}


here the output:
screen shot of my app



and how the above screen to convert like this:
screen shot of music player



Here the project source:https://github.com/udayoleti/XAMARIN



thanks in advance.







android xamarin xamarin.android android-gridview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 9:30









CGPA6.4

2,4721929




2,4721929










asked Nov 22 at 17:59









Uday Oleti

33




33












  • You are fetching instance of few controls incorrectly. var albumImage = view.. this should be holder.AlbumName=view.... If you are getting instances outside of holder than no meaning of using holder class. Even albumName.SetTextColor this should be holder.albumName.SetTextColor.
    – CGPA6.4
    Nov 23 at 9:28




















  • You are fetching instance of few controls incorrectly. var albumImage = view.. this should be holder.AlbumName=view.... If you are getting instances outside of holder than no meaning of using holder class. Even albumName.SetTextColor this should be holder.albumName.SetTextColor.
    – CGPA6.4
    Nov 23 at 9:28


















You are fetching instance of few controls incorrectly. var albumImage = view.. this should be holder.AlbumName=view.... If you are getting instances outside of holder than no meaning of using holder class. Even albumName.SetTextColor this should be holder.albumName.SetTextColor.
– CGPA6.4
Nov 23 at 9:28






You are fetching instance of few controls incorrectly. var albumImage = view.. this should be holder.AlbumName=view.... If you are getting instances outside of holder than no meaning of using holder class. Even albumName.SetTextColor this should be holder.albumName.SetTextColor.
– CGPA6.4
Nov 23 at 9:28



















active

oldest

votes











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%2f53436183%2fxamarin-android-gridview-mess-up-after-scrolling%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53436183%2fxamarin-android-gridview-mess-up-after-scrolling%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

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...