Много раз видели эту проблему, я использую адаптер клиента для заполнения списка ListView с помощью моего макета клиента xml. Я понимаю, что щелчок вероятно не собирается Перечислите вид и мой макет блокирует его, но после того, как не попробовав возможные решения ничего, кажется, пытается:Listview OnItemClickListener с неработающим адаптером клиента
Пробовал: андроида: descendantFocusability = «blocksDescendants» для макета моего обычая XML
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
для каждого отдельных элементов в макете
Любой другой способ решения этой проблемы
EDIT
Добавление кода для того, где ListView крепится к адаптеру:
if(!allcontactsstring.isEmpty()){
adapter = new MyContactListAdapter(getContext(),R.layout.contact_list_view,imageArry);
listView.setAdapter(adapter);
}
AdapterView.OnItemClickListener mylistViewClicked = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getContext(),"S"+position,Toast.LENGTH_LONG);
}
};
listView.setOnItemClickListener(mylistViewClicked);
Мой заказ адаптер:
public class MyContactListAdapter extends ArrayAdapter<MySQLiteContact> {
Context context;
int layoutResourceId;
ArrayList<MySQLiteContact> data=new ArrayList<MySQLiteContact>();
public MyContactListAdapter(Context context, int resource, ArrayList<MySQLiteContact> objects) {
super(context, resource, objects);
//this.layoutResourceId = layoutResourceId;
this.layoutResourceId = resource;
this.context = context;
this.data = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
//ImageView tmp = (ImageView)row.findViewById(R.id.icon);
//tmp.clearFocus();
//tmp.isClickable();
//TextView tmp1=(TextView)row.findViewById(R.id.Itemname);
//tmp1.clearFocus();
holder = new ImageHolder();
holder.txtTitle = (TextView)row.findViewById(R.id.Itemname);
holder.imgIcon = (ImageView)row.findViewById(R.id.icon);
row.setTag(holder);
}
else
{
holder = (ImageHolder)row.getTag();
}
MySQLiteContact picture = data.get(position);
holder.txtTitle.setText(picture.getsFirstName()+" "+picture.getsLastName());
byte[] outImage=picture.getBimage();
ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
theImage=Bitmap.createScaledBitmap(theImage , 100, 100, true);
theImage= ContactDetailsMain.getRoundedRectBitmap(theImage,100);
holder.imgIcon.setImageBitmap(theImage);
return row;
}
static class ImageHolder
{
ImageView imgIcon;
TextView txtTitle;
}
}
Мой XML с точки зрения текста и ImageView:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants">
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
android:src="@drawable/ic_contact_picture_holo_light"
/>
<TextView
android:id="@+id/Itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="@color/black"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
android:paddingTop="5dp"
/>
</LinearLayout>
EDIT Грязных обходной
Как падла и грязное обходного я добавил на клик слушателя внутри адаптера к каждому макету, который получает раздут и это похоже на работу в настоящее время, чтобы получить позиции ,
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println(position);
}
});
Не в чистоте, чтобы иметь так много слушателей, было бы неплохо иметь только один, но да на данный момент он работает ..
* Я понимаю, щелчок, вероятно, никогда не будет Перечислите вид, и мой макет блокирует его *, что вы имеете в виду именно это? можете ли вы расширить или уточнить? спасибо –
@jordi Castilla, у меня есть линейная компоновка с представлением изображения и текстом. Именно этот макет заполняется в каждом элементе моего списка. Так что, если я нажму на listview, мой клик будет поднят OnItemClickListener моего списка? , –
, если вы добавили слушателя в свой «ListView», тогда да. –