1
I’ve been ListView
layout.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
xmlns:ads = "http://schemas.android.com/apk/res-auto"
android:background="#ffffff"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/praias"
android:layout_centerHorizontal="true"
android:layout_above="@+id/adView" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_unit_id"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
Main.class
:
adapter = new AdapterListView(MainActivity.this,this,itens,height,width,daoItem,getPackageName());
praias.setAdapter(adapter);
praias.setClickable(true);
Adapter.class
:
public View getView(final int position, View v, ViewGroup parent) {
view = mInflater.inflate(R.layout.layoutlist, null);
final ListenerItem categoria = itens.get(position);
TextView nomePraia = (TextView) view.findViewById(R.id.nomePraia);
ImageView foto = (ImageView) view.findViewById(R.id.fotoPraia);
final ImageButton btFavorito = (ImageButton) view.findViewById(R.id.btFavorito);
TextView descricao = (TextView) view.findViewById(R.id.descricao);
final Button bt = (Button) view.findViewById(R.id.bt);
Button btVerMais = (Button) view.findViewById(R.id.btVerMais);
String desc="";
if(categoria.descricao.length()<397){
btVerMais.setVisibility(View.INVISIBLE);
desc=categoria.descricao;
}else{
for(int i=0;i<397;i++){
desc=desc+categoria.descricao.charAt(i);
}
desc=desc+"...";
}
nomePraia.setText(categoria.nome);
String nome_foto = categoria.nome_foto;
int drawableId = context.getResources().getIdentifier(nome_foto, "drawable", packageName);
Log.e(R.drawable.itanhaem3+"",drawableId+"");
Bitmap bm = BitmapFactory.decodeResource(context.getResources(), drawableId);
bm = bm.createScaledBitmap(bm, width, width, true);
foto.setImageBitmap(bm);
descricao.setText(desc);
if (categoria.favorito) {
btFavorito.setImageResource(R.drawable.ic_action_favorite_v);
} else {
btFavorito.setImageResource(R.drawable.ic_action_favorite);
}
btVerMais.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ListenerItem listenerItem = new ListenerItem();
listenerItem = itens.get(position);
open(listenerItem);
}
});
btFavorito.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ListenerItem listenerItem = new ListenerItem();
listenerItem = itens.get(position);
if (listenerItem.favorito) {
listenerItem.favorito = false;
btFavorito.setImageResource(R.drawable.ic_action_favorite);
chamaToast(false);
} else {
listenerItem.favorito = true;
btFavorito.setImageResource(R.drawable.ic_action_favorite_v);
chamaToast(true);
}
try {
daoItem.createOrUpdate(listenerItem);
} catch (SQLException e) {
e.printStackTrace();
}
}
});
activity.registerForContextMenu(bt);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bt.setId(position);
activity.openContextMenu(bt);
}
});
return view;
}
public void open(ListenerItem listenerItem){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setMessage(Html.fromHtml(listenerItem.descricao));
alertDialogBuilder.setPositiveButton(R.string.voltar,null);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
Whenever this going from one item to the other hangs a little , I do not know why it is so slow this ListView
Screenshots:
How so is crashing, you mean at upgrade time?
– Wellington Avelino
as you go down the scroll , going to the items below, there it is slow, it seems that and time to load the item below
– Ilgner de Oliveira
Actually the items are already loaded.. has images in this listview?
– Wellington Avelino
yes, there’s an image. I’ll put a picture
– Ilgner de Oliveira