getListView().setItemsCanFocus(true); Change to true as like this... it will work then
On Wed, Jun 3, 2009 at 6:23 PM, Tom <thomas.coz...@gmail.com> wrote: > > public class UserList extends ListActivity implements > AdapterView.OnItemClickListener{ > > private Client client; > private ArrayList<User> users = new ArrayList<User>(); > private UserAdapter userAdapter; > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.user_list); > getListView().setItemsCanFocus(false); > getListView().setOnItemClickListener(this); > > 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(); > > Log.i(getClass().getSimpleName(),"Display users"); > for(int j=0;j<users.size();j++) > { > this.userAdapter.add(users.get(j)); > } > setListAdapter(this.userAdapter); > > } > } > } > > > @Override > public void onItemClick(AdapterView<?> adapterView, View view, int > position, long id) > { > Log.d(getClass().getSimpleName(), " -- Click -- "); > } > > // Adapter > 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; > } > > > class ViewHolder { > TextView firstNameText; > TextView lastNameText; > TextView phoneNumberText; > TextView statusText; > } > > public long getItemId(int position) { > return position; > } > > } > > > On 3 juin, 13:35, guna <gunaz...@gmail.com> wrote: > > Post your latest code... So that its easy to correct the errors.... Check > > whether enabled the listitems..... > > > > On Wed, Jun 3, 2009 at 4:59 PM, Tom <thomas.coz...@gmail.com> wrote: > > > > > 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. > > > > > On 3 juin, 13:23, guna <gunaz...@gmail.com> wrote: > > > > Ask clearly your questions........ > > > > > > On Wed, Jun 3, 2009 at 4:45 PM, Tom <thomas.coz...@gmail.com> wrote: > > > > > > > I just want to notice that the Layout for the ArrayAdapter contains > > > > > checkbox. > > > > > > > On 3 juin, 11:33, Tom <thomas.coz...@gmail.com> wrote: > > > > > > 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 > > > > ... > > > > plus de détails » > > > -- 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 -~----------~----~----~----~------~----~------~--~---