Ok
I added to my class "implements AdapterView.OnItemClickListener".
Then I implemented "onItemClickListener" method and added in
"onCreate" "setOnClickListener(this)".

Now I can select and highlight items but only with the trackball.
Nothing happens with the mouse event.

May have implement "OnItemSelectedListener" too ?

Thanks
Tom

On 2 juin, 16:47, guna <gunaz...@gmail.com> wrote:
> Tom,
>
> You didnt implements OnItemClickListener, and also in oncreate add
> setonitemclicklistener(this)....
>
>
>
> On Tue, Jun 2, 2009 at 8:10 PM, Tom <thomas.coz...@gmail.com> wrote:
>
> > These are my line of codings :
>
> > public class UserList extends ListActivity{
>
> >    private Client client;
> >    private ArrayList<User> users = new ArrayList<User>();
> >    private UserAdapter userAdapter;
> >    public static final int MENU_ITEM_VIEW = Menu.FIRST;
> >    private static final int COLUMN_INDEX_TITLE = 1;
>
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.user_list);
>
> >        Intent i = getIntent();
> >        if (i!= null)
> >        {
> >                if (i.getAction().equalsIgnoreCase(Intent.ACTION_VIEW))
> >                {
> >                this.client = (Client) i.getSerializableExtra
> > (Constants.CLIENT_CLASS_NAME);
>
> >                this.userAdapter = new UserAdapter(this,
> > R.layout.user_row, users);
> >                users = (ArrayList<User>) this.client.getUsers();
> >                for(int j=0;j<users.size();j++)
> >                {
> >                        this.userAdapter.add(users.get(j));
> >                }
> >                setListAdapter(this.userAdapter);
> >                }
> >        }
> >    }
>
> >    private class UserAdapter extends ArrayAdapter<User>{
>
> >        private LayoutInflater mInflater;
> >        private ArrayList<User> items;
>
> >        public UserAdapter(Context context, int resourceId,
> > ArrayList<User> items)
> >        {
> >            super(context, resourceId, items);
> >            mInflater = LayoutInflater.from(context);
> >            this.items = items;
> >        }
>
> >        public boolean areAllItemsSelectable()
> >        {
> >            return true;
> >        }
>
> >        public boolean isEnabled(int position) {
> >            if (position >= 0 && position <= items.size()) {
> >                return true;
> >            }
> >            return false;
> >        }
>
> >        public int getCount() {
> >            return items.size();
> >        }
>
> >        public User getItem(int position) {
> >              if (0 == position) {
> >                  return null;
> >              }
> >              return items.get(position);
> >         }
>
> >       �...@override
> >        public View getView(int position, View convertView, ViewGroup
> > parent) {
>
> >            ViewHolder holder = null;
> >            View v = convertView;
> >            User user = items.get(position);
>
> >            if (v == null) {
> >                mInflater = (LayoutInflater)getSystemService
> > (Context.LAYOUT_INFLATER_SERVICE);
> >                v = mInflater.inflate(R.layout.user_row, null);
>
> >                    if (user != null) {
> >                        // Creates a ViewHolder and store references to the
> > two children views
> >                        // we want to bind data to.
> >                        holder = new ViewHolder();
> >                        holder.firstNameText = (TextView) v.findViewById
> > (R.id.user_first_name);
> >                        holder.lastNameText = (TextView) v.findViewById
> > (R.id.user_last_name);
> >                        holder.phoneNumberText = (TextView) v.findViewById
> > (R.id.user_phone_number);
> >                        holder.statusText = (TextView) v.findViewById
> > (R.id.user_status);
> >                    }
>
> >                    v.setTag(holder);
> >            }
> >                else
> >                {
> >                holder = (ViewHolder) v.getTag();
> >                }
>
> >            if (holder.firstNameText != null) {
> >                holder.firstNameText.setText(user.getFirstName());
> >            }
> >            if (holder.lastNameText != null){
> >                holder.lastNameText.setText(user.getLastName());
> >            }
> >            if ( holder.phoneNumberText != null){
> >                 holder.phoneNumberText.setText(user.getPhoneNumber());
> >            }
> >            if (holder.statusText != null){
> >                holder.statusText.setText(String.valueOf(user.getStatus
> > ()));
> >            }
>
> >            return v;
> >        }
>
> >        private class ViewHolder {
> >            TextView firstNameText;
> >            TextView lastNameText;
> >            TextView phoneNumberText;
> >            TextView statusText;
> >        }
>
> >        public long getItemId(int position) {
> >            return position;
> >        }
>
> >    }
>
> >   �...@override
> >    public void onCreateContextMenu(ContextMenu menu, View view,
> > ContextMenuInfo menuInfo) {
> >        AdapterView.AdapterContextMenuInfo info;
> >        try {
> >             info = (AdapterView.AdapterContextMenuInfo) menuInfo;
> >        } catch (ClassCastException e) {
> >            Log.e(getClass().getSimpleName(), "bad menuInfo", e);
> >            return;
> >        }
>
> >        Cursor cursor = (Cursor) getListAdapter().getItem
> > (info.position);
> >        if (cursor == null) {
> >            return;
> >        }
>
> >        menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));
> >        menu.add(0, MENU_ITEM_VIEW, 0,
> > R.string.localization_user_view);
> >    }
>
> >   �...@override
> >    public boolean onContextItemSelected(MenuItem item) {
> >        AdapterView.AdapterContextMenuInfo info;
> >        try {
> >             info = (AdapterView.AdapterContextMenuInfo)
> > item.getMenuInfo();
> >        } catch (ClassCastException e) {
> >            Log.e(getClass().getSimpleName(), "bad menuInfo", e);
> >            return false;
> >        }
>
> >        switch (item.getItemId()) {
> >            case MENU_ITEM_VIEW: {
> >            }
> >        }
> >        return false;
> >    }
>
> >   �...@override
> >    protected void onListItemClick(ListView l, View v, int position,
> > long id) {
> >        Uri uri = ContentUris.withAppendedId(getIntent().getData(),
> > id);
>
> >        String action = getIntent().getAction();
> >        if (Intent.ACTION_PICK.equals(action) ||
> > Intent.ACTION_GET_CONTENT.equals(action)) {
> >            setResult(RESULT_OK, new Intent().setData(uri));
> >        } else {
> >            startActivity(new Intent(Intent.ACTION_EDIT, uri));
> >        }
> >    }
>
> > }
>
> > Thanks
> > Tom
>
> > On 2 juin, 15:51, guna <gunaz...@gmail.com> wrote:
> > > Its good if you posted your line of codings?
> > > listview.setOnItemClickListener()
>
> > > Guna
>
> > > On Tue, Jun 2, 2009 at 7:17 PM, Tom <thomas.coz...@gmail.com> wrote:
>
> > > > Which listener do you think?
>
> > > > In fact , when I scroll in the ListView with the mouse, I can see
> > > > items highlighted.
> > > > But when I click on the item, nothing happens (item's color doesn't
> > > > change).
>
> > > > On 2 juin, 15:31, guna <gunaz...@gmail.com> wrote:
> > > > > Do you set the listener first???
>
> > > > > On Tue, Jun 2, 2009 at 6:58 PM, Tom <thomas.coz...@gmail.com> wrote:
>
> > > > > > I added areAllItemsSelectable and isSelectable methods but it still
> > > > > > doesn't work.
> > > > > > Do you have an other idea?
>
> > > > > > Best regards
> > > > > > Tom
>
> > > > > > On 2 juin, 13:24, Guru <gurudut...@gmail.com> wrote:
> > > > > > > Probably u have returned false in  areAllItemsEnabled  in the
> > adapter
>
> > > > > > > or
> > > > > > > returning false in isEnabled(position)
>
> > > > > > > On Tue, Jun 2, 2009 at 4:36 PM, Tom <thomas.coz...@gmail.com>
> > wrote:
>
> > > > > > > > Hi,
>
> > > > > > > > I developped a ListView with a custom adapter (which extends
> > > > > > > > ArrayAdapter).
> > > > > > > > The problem is that i can't selected or highlighted items.
> > > > > > > > Is there a attribut to fix in the listView Layout or something
> > > > else?
>
> > > > > > > > Best regards,
> > > > > > > > Tom
>
> > > > > > > --
> > > > > > > Thanks and Regards
> > > > > > > Gurudutt P.S.
>
> > > > > --
> > > > > Guna
>
> --
> Guna
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to