![]() |
|
| Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android |
«
Tema Anterior
|
Siguiente tema
»
|
|
Herramientas |
|
#1
|
|
Problema listview itemclick
Buenas compañeros , tengo un navigation drawer con su listview en mi app , este tiene 4 tipos de items dos de ellos son clickables y hacen una funcion , el problema es que unio de estos no oye el clicklistener y ni siquiera puedo adaptarle el selctor xml cosa que el otro si.
bueno este es el adapter del lisview: Código:
private static class Item {
String mTitle;
int mIconRes;
Item(String title, int iconRes) {
mTitle = title;
mIconRes = iconRes;
}
}
private static class UserProfile {
String mUser;
String avatarurl;
UserProfile(String name, String imgAvatarUrl) {
mUser = name;
avatarurl = imgAvatarUrl;
}
}
private static class UserNews {
int mIconRes;
String mTitle;
String nCounter;
UserNews(String title, String counter, int iconres) {
mTitle = title;
nCounter = counter;
mIconRes = iconres;
}
}
private static class Category {
String mTitle;
Category(String title) {
mTitle = title;
}
}
private class MenuAdapter extends BaseAdapter {
private List<Object> mItems;
MenuAdapter(List<Object> items) {
mItems = items;
}
@Override
public int getCount() {
return mItems.size();
}
@Override
public Object getItem(int position) {
return mItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return getItem(position) instanceof Item ? 0 : 1;
}
@Override
public int getViewTypeCount() {
return 4;
}
@Override
public boolean isEnabled(int position) {
return getItem(position) instanceof Item;
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
public void setbadgePost(int count) {
Object obj=mItems.get(12);
if(obj instanceof UserNews) {
UserNews us=(UserNews)obj;
us.nCounter=String.valueOf(count);
}
}
public void setbadgeMps(int count) {
Object obj=mItems.get(13);
if(obj instanceof UserNews) {
UserNews us=(UserNews)obj;
us.nCounter=String.valueOf(count);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
Object item = getItem(position);
if (item instanceof UserProfile) {
if (v == null) {
v = getLayoutInflater().inflate(R.layout.item_profile_user,
parent, false);
}
ImageView imUser = (ImageView) v
.findViewById(R.id.imageUserProfile);
TextView tv = (TextView) v.findViewById(R.id.textuserprofile);
new DownloadImageTask(imUser)
.execute(((UserProfile) item).avatarurl);
tv.setText(((UserProfile) item).mUser);
} else if (item instanceof Category) {
if (v == null) {
v = getLayoutInflater().inflate(R.layout.menu_row_category,
parent, false);
}
((TextView) v).setText(((Category) item).mTitle);
} else if (item instanceof UserNews) {
if (v == null) {
v = getLayoutInflater().inflate(R.layout.usernews_item,
parent, false);
}
TextView ttitle = (TextView) v.findViewById(R.id.textTitle);
TextView tbadge = (TextView) v.findViewById(R.id.textbadge);
ttitle.setText(((UserNews) item).mTitle);
ttitle.setCompoundDrawablesWithIntrinsicBounds(
((UserNews) item).mIconRes, 0, 0, 0);
tbadge.setText(((UserNews) item).nCounter);
} else {
if (v == null) {
v = getLayoutInflater().inflate(R.layout.menu_row_item,
parent, false);
}
TextView tv = (TextView) v;
tv.setText(((Item) item).mTitle);
tv.setCompoundDrawablesWithIntrinsicBounds(
((Item) item).mIconRes, 0, 0, 0);
}
return v;
}
}
Código:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/MenuDrawer.Widget.Title" />
Código:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/md__list_selector_holo_dark" >
<TextView
android:id="@+id/textTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingBottom="8dp"
android:paddingLeft="10dp"
android:paddingRight="32dp"
android:paddingTop="8dp"
android:text="title"
android:textAppearance="?android:attr/textAppearance"
android:textColor="@color/Black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/textbadge"
style="@style/MenuDrawer.badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="19dp"
android:text="0"
android:textSize="16sp" />
</LinearLayout>
Última edición por rafaxplayer Día 07/12/14 a las 12:14:08 |
|
|
|
#2
|
|
Solucionado , era el método isEnabled del adapter que solo retornaba true si era instancia a Item y no a Usernews
|
| Respuesta |
Estás aquí
|
||||||
|
||||||
«
Tema Anterior
|
Siguiente tema
»
|
|
Hora actual: 14:32:10 (GMT +1)
HTCMania: líderes desde el 2007





