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