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

Respuesta
 
Herramientas
  #1  
Viejo 06/12/14, 10:33:36
Array

[xs_avatar]
rafaxplayer rafaxplayer no está en línea
Miembro del foro
 
Fecha de registro: jun 2013
Localización: en la barcelona media
Mensajes: 224
Modelo de smartphone: LG-E610
Tu operador: Orange
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;
		}

	}
Los xml este simple basado en textview usado en la clase "Item" y "Category" ,si me funciona a la perfección:

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" />
Este compuesto es el de la clase "UserNews" que no detecta el listener ni se aplica el selector:

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>
Bueno los dos grandes problemas son que los items de "UserNews" no funcionan ni en el listener ni el selector y he probado mil combinaciones y posibles soluciones de inet , pero nada... no se que hacer mas , se aceptan todas las sugerencias

Última edición por rafaxplayer Día 07/12/14 a las 12:14:08.
Responder Con Cita


  #2  
Viejo 07/12/14, 12:15:19
Array

[xs_avatar]
rafaxplayer rafaxplayer no está en línea
Miembro del foro
 
Fecha de registro: jun 2013
Localización: en la barcelona media
Mensajes: 224
Modelo de smartphone: LG-E610
Tu operador: Orange
Solucionado , era el método isEnabled del adapter que solo retornaba true si era instancia a Item y no a Usernews
Responder Con Cita
Respuesta

Estás aquí
Regresar   Portal | Indice > Todo sobre Android > Programación y Desarrollo para Android



Hora actual: 11:57:39 (GMT +1)



User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.

Contactar por correo / Contact by mail / 邮件联系 /