0

i tried to add a listener to that list but nothing i don't understand why if you want to see the rest of the code please check on add your own listener to a list

public void onCreatebis(final ResolveInfo resolveInfo)  {

            setContentView(R.layout.main);
            final Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER) ;
            final PackageManager pm = getApplicationContext().getPackageManager();
            final ArrayList<ResolveInfo> listP= (ArrayList<ResolveInfo>)                    pm.queryIntentActivities( mainIntent, 0);
            final int trimLength = "com.android.".length();
            ArrayList<String> maliste = new ArrayList<String>();
                        // Loop over each item.
            for (ResolveInfo info : listP) {
                // Get the (full, qualified) package name.
                String packag = info.activityInfo.applicationInfo.packageName;

                // Now, trim it with substring and the trim length.
                String trimmed = packag.substring(trimLength);
                maliste.add(trimmed);
            }
            ListView list = (ListView)findViewById(R.id.list);
            monadaptateur adapter2 = new monadaptateur(this, maliste);

            list.setOnItemClickListener(new OnItemClickListener(){

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    Log.v("lalalala","lalala");

                }
                   });
            list.setAdapter(adapter2);
    }
Community
  • 1
  • 1
Sharp
  • 121
  • 1
  • 2
  • 16

1 Answers1

2

if the ListView has focusable items then onClickListener will fire instead of the onItemClickListener. Set items can focus to false

list.setItemsCanFocus(false);

have a look at this thread. Also note there are workarounds for this. But the better choice would be to set items non focusable and use OnItemClickListener, or make them focusable and use an onClickListener on the views

Also, the onClickListener should not be set for the listview. Instead for each listview item in the getView() method

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // ...

    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // your code
        }

    });

    return view;
}
Community
  • 1
  • 1
Ahmed Aeon Axan
  • 2,139
  • 1
  • 17
  • 30
  • even my log isn't display public void onItemClick(AdapterView> parent, View view, int position, long id) {Toast.makeText(DvpList2.this, "je suis là!", Toast.LENGTH_SHORT).show(); } – Sharp Mar 13 '13 at 10:17
  • http://stackoverflow.com/questions/3451947/onlistitemclick-not-working-for-listview-in-android i've seen that and even that dfoesn't work – Sharp Mar 15 '13 at 13:59