0

I encountered a silly problem. I have an identical thing working already, but for the second try, the onItemClick is not doing anything. I re-re-rechecked so many times now, but nothing seems to catch my eye. Please take a look and let me know what is wrong So here is my setup.

The activity:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_promotionale);
        ListView mylist = (ListView) findViewById(R.id.lv_promotionale);
        mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                Toast.makeText(PromotionaleActivity.this,"I touched an item at position"+Integer.toString(position),Toast.LENGTH_SHORT).show();
            }
        });

The activity layout is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="370dp"
            android:id="@+id/lv_promotionale" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="65dp"
            android:weightSum="1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Some text here"
                android:id="@+id/textView"
                android:paddingLeft="15dp"
                android:paddingStart="15dp"
                android:paddingTop="15dp"
                android:paddingRight="0dp"
                android:paddingEnd="0dp"
                android:paddingBottom="0dp" />

        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

EDIT Here is the method where I load my listview with data using an external adapter

 public void LoadListWithStuff(){
        SQLiteDatabase db = new myDbHelper(getApplicationContext()).getWritableDatabase();
        Cursor mCursor = db.rawQuery("select _id,data,numar,idclient,numeclient,tipclient,trimisa from cereri_mst order by data,numar desc" , null);
        idid.clear();
        idclient.clear();
        numeclient.clear();
        tipclient.clear();
        datacerere.clear();
        numarcerere.clear();
        trimisa.clear();

        if (mCursor.moveToFirst()) {
            do {
                idid.add(Integer.toString(mCursor.getInt(0)));
                datacerere.add(mCursor.getString(1));
                numarcerere.add(mCursor.getString(2));
                idclient.add(Integer.toString(mCursor.getInt(3)));
                numeclient.add(mCursor.getString(4));
                tipclient.add(mCursor.getString(5));
                trimisa.add(mCursor.getString(6));
            } while (mCursor.moveToNext());
        }
        DisplayCereriAdapter disadpt = new DisplayCereriAdapter(PromotionaleActivity.this,idid,idclient,
                numeclient, tipclient,datacerere,numarcerere,trimisa);

        ListView lv = (ListView) findViewById(R.id.lv_promotionale);
        lv.setAdapter(disadpt);
        mCursor.close();
        db.close();

    }

Also, I must say here that the listview is populated. I can see the contents of the listView. The only problem is that I cannot seem to catch the ItemClick and longClick events on the listview...

Why doesn't it work????? I am going crazy here... Thank you

user1137313
  • 2,390
  • 9
  • 44
  • 91
  • Are you setting `adapter` to your `listview` – Rustam Oct 13 '14 at 16:43
  • yes. I will add above the code where I set it – user1137313 Oct 13 '14 at 16:49
  • put a break point before `mylist.setOnItemClickListener(...)` and debug it. because from code it look fine. – Rustam Oct 13 '14 at 16:51
  • check if your activity implement OnItemClickListener – TooCool Oct 13 '14 at 16:58
  • do you set View.onClickListener on the views in your DisplayCereriAdapter - if so the itemClickListener might not be called anymore – Simon Meyer Oct 13 '14 at 17:00
  • I found the problem... Now what is the solution???? So the probl;em is the checkBox that I have on my layout of the ITEM. So if I remove the checkBox from the layout, all works like expected, but if I add the checkbox, no events are captured on my listView item. What to do? – user1137313 Oct 13 '14 at 17:02
  • Simon Meyer - I set the listener in the onCreate of the Activity, so no - not in the Adapter – user1137313 Oct 13 '14 at 17:23
  • If anyone has a solution to allow me to use checkbox-es in the item layout, please post the solution as an answer and I will accept it – user1137313 Oct 13 '14 at 17:24

1 Answers1

0

The solution I found was to stop using the checkBox and replace it with ImageView... Now all works fine

user1137313
  • 2,390
  • 9
  • 44
  • 91
  • You could also look into something like this http://stackoverflow.com/questions/5417339/android-listview-with-checkbox-and-all-clickable if you wanted to keep the checkbox – Mike Oct 13 '14 at 17:24