开发者

Item's ClickListener disable HighLight on Item touch

I have List of items. I'm using custom adapter (Android 1.5). Everything works perfectly, until I reached the point when I add item's ClickListener to each Item.

When I do that, I lose the "focus effect", when the user touch at any item.

The mechanism works fine, but visually I cant see the red background which surrounding the item when the user clicks on it.

Any idea why?

Some code:

my arrayAdapter:

public class OrderAdapter extends ArrayAdapter<Order> {
    private ArrayList<Order> items;
    private Context mContext;

    public OrderAdapter(Context context, int textViewResourceId, ArrayList<Order> items) {
        super(mContext, textViewResourceId, items);
        this.items = items;
        this.mContext = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if (v == null) {
            LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }
        Order o = items.get(position);
        v.setOnClickListener((new OnItemClickListener(position, o)));
        if (o != null) {
            TextView tt = (TextView) v.findViewById(R.id.TxtType);
            TextView bt = (TextView) v.findViewById(R.id.txtTimeCreated);
            if (tt != null) {
                tt.setText("סוג תעודה מזהה: " + o.getIdType());
        }
        if (bt != null) {
            bt.setText("זמן יצירת התמונה: " + o.getCreateDate());
        }
        return v;
    }

    private class OnItemClickLi开发者_JS百科stener implements OnClickListener {
        private int mPosition;
        private Order mItem;

        OnItemClickListener(int position, Order item) {
            mPosition = position;
            mItem = item;
            //mItem.setmChecked(false);
        }

        @Override
        public void onClick(View v) {
            int x = mPosition;
            int z = 0;
        }
    }
}

this is the row.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="100sp"
    android:padding="6dip">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/certificate"
        android:id="@drawable/certificate"
        android:layout_marginLeft="6dip"
        android:clickable="false"/>

    <LinearLayout
        android:id="@+id/LinearLayout01"
        android:orientation="vertical"
        android:layout_width="1sp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="right"
        android:focusableInTouchMode="true"
        android:focusable="true"
        android:clickable="true">

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:clickable="false"
            android:id="@+id/TxtType"
            android:text="סוג תעודה מזהה"/>

        <TextView
            android:singleLine="true"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginBottom="3dip"
            android:id="@+id/txtTimeCreated"
            android:text="זמן יצירת התמונה"/>
    </LinearLayout>
</LinearLayout>

Any ideas will be welcome,

Thanks,

ray.


why are you writing the click listner in the adapter. Instead you need to setOnItemClickListner for the listView inside the activity and handle it there. By doing this u will get the highlight since your individual list items will not have listeners anymore

yourListView.setOnItemClickListener(new OnItemClickListener()
{
    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
    {
         // whatever u want do it here, not in the adapter.

    }
});

By doing this u will get your highlight back

NOTE: you need these imports.

import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜