Created
June 14, 2017 02:28
-
-
Save anonymous/b07c8c02357afb9f8d75b01848bea5b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Android.App; | |
using Android.Content; | |
using Android.OS; | |
using Android.Runtime; | |
using Android.Views; | |
using Android.Widget; | |
namespace GR3_chat_client | |
{ | |
class customadaptadorburbuja : BaseAdapter | |
{ | |
public List<Actividadchat.textomasid> textoyid = new List<Actividadchat.textomasid>(); | |
Context context; | |
List<string> listillaa = new List<string>(); | |
string nombre = ""; | |
public customadaptadorburbuja(Context context, List<Actividadchat.textomasid> listilla, string nombree) | |
{ | |
this.context = context; | |
textoyid = listilla; | |
nombre = nombree; | |
} | |
public override Java.Lang.Object GetItem(int position) | |
{ | |
return textoyid[position].texto; | |
} | |
public override long GetItemId(int position) | |
{ | |
return textoyid[position].id; | |
} | |
public override View GetView(int position, View convertView, ViewGroup parent) | |
{ | |
if (textoyid[position].texto.Split('¹')[0] == nombre) | |
{ | |
var view = convertView; | |
customadaptadorburbujaViewHolder holder = null; | |
if (view != null) | |
{ | |
holder = view.Tag as customadaptadorburbujaViewHolder; | |
} | |
if (holder == null) | |
{ | |
holder = new customadaptadorburbujaViewHolder(); | |
var inflater = context.GetSystemService(Context.LayoutInflaterService).JavaCast<LayoutInflater>(); | |
//replace with your item and your holder items | |
//comment back in | |
view = inflater.Inflate(Resource.Layout.chatsitosderecha, parent, false); | |
holder.Title = view.FindViewById<TextView>(Resource.Id.textView1); | |
view.Tag = holder; | |
} | |
string texto = textoyid[position].texto.Split('¹')[1]; | |
holder.Title.Text = "Yo:" + texto; | |
return view; | |
} | |
else { | |
var view = convertView; | |
customadaptadorburbujaViewHolder holder = null; | |
if (view != null) | |
{ | |
holder = view.Tag as customadaptadorburbujaViewHolder; | |
} | |
if (holder == null) | |
{ | |
holder = new customadaptadorburbujaViewHolder(); | |
var inflater = context.GetSystemService(Context.LayoutInflaterService).JavaCast<LayoutInflater>(); | |
//replace with your item and your holder items | |
//comment back in | |
view = inflater.Inflate(Resource.Layout.chatsitos, parent, false); | |
holder.Title = view.FindViewById<TextView>(Resource.Id.textView1); | |
view.Tag = holder; | |
} | |
string texto = textoyid[position].texto.Split('¹')[1]; | |
holder.Title.Text = textoyid[position].texto.Split('¹')[0] + ":" + texto; | |
return view; | |
} | |
//fill in your items | |
} | |
//Fill in cound here, currently 0 | |
public override int Count | |
{ | |
get | |
{ | |
return textoyid.Count; | |
} | |
} | |
} | |
class customadaptadorburbujaViewHolder : Java.Lang.Object | |
{ | |
//Your adapter views to re-use | |
public TextView Title { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unas cuantas sugerencias:
`
class Mensaje
{
public string Usuario {get; set;}
public string Texto {get; set;}
public DateTime Fecha {get; set;}
}
`
textoyid[position]
mejor crea una variable con el valor de este ejemplovar item = textoyid[position];
así le evitas al procesador tener que buscar ese item en tu collection las 700 veces que lo usas. Lo mismo con el Split().string
pero si creas una entidad (la 3ra sugerencia) puedes hacer que tu BaseAdapter maneje tus items sin tener que estar haciendo casting a Java.Object. EjBaseAdapter<Mensaje>
.