I have my class MainActivity which extends ListActivity, i set the adapter to list via custom adapter in onResume()
method.
@Override
protected void onResume()
{
super.onResume();
this.setListAdapter(null);
adapter=new ContactListAdapter(this, R.id.txvNNPersonId, helper.getContacts(sortByname));
setListAdapter(adapter);
}
to handle list item click, i use this
protected void onListItemClick(ListView l, View v, int position, long id)
{
RelativeLayout r=(RelativeLayout)v;
TextView txvPersonId=(TextView)r.getChildAt(0);
int iid=Integer.parseInt(txvPersonId.getText().toString());
Intent intent=new Intent(this,ViewContactActivity.class);
intent.putExtra("id", iid);
startActivityForResult(intent, VIEW_RECORD);
//these is not working, these event is not raised, when clicked on listitem click
}
but it does not work when click/touch on item via mouse, it only works when i use it with item selected and implementing onItemSelectedListener
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
RelativeLayout r=(RelativeLayout)arg1;
TextView txvPersonId=(TextView)r.getChildAt(0);
int id=Integer.parseInt(txvPersonId.getText().toString());
Intent intent=new Intent(this,ViewContactActivity.class);
intent.putExtra("id", id);
startActivityForResult(intent, VIEW_RECORD);
}
and this only works with the arrow keys on emulator, but on real devices,(usually)they do not have arrow/navigation keys, how to define click for list item?
EDIT:the row_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:longClickable="true"
android:orientation="horizontal">
<TextView android:id="@+id/txvPersonId"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:visibility="invisible" /> -->
<!-- this is name -->
<TextView android:id="@+id/txvPersonName"
android:layout_marginLeft="5dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:text="asd"
android:textSize="15sp"
android:paddingBottom="5dp" />
</RelativeLayout>`