I encoded my own adapter and added it to my ListActivity via ListView. The reason I wrote my own adapter is because I had to make some changes to the list in the list entry. In each list entry, I have 3 TextViews.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="6dip"> <TextView android:id="@+id/myNr" android:layout_width="40dip" android:layout_height="fill_parent" android:layout_marginRight="15dip" android:text="id" android:textSize="25dip" android:background="#333333" android:gravity="center_horizontal"/> <LinearLayout android:orientation="vertical" android:layout_width="0dip" android:layout_weight="1" android:layout_height="fill_parent"> <TextView android:id="@+id/editor" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center_vertical" android:text="Editor: " /> <TextView android:id="@+id/date" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:singleLine="true" android:ellipsize="marquee" android:text="Date: " /> </LinearLayout>
The next thing I did was implement the "onListItemClick-Methode". Subsequently, I implemented onListItemLongClick-Listener with the following code:
in onCreate of Activity I added:
registerForContextMenu(getListView());
then I added the following method:
Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo){ AdapterView.AdapterContextMenuInfo info; info = (AdapterView.AdapterContextMenuInfo) menuInfo; long id = getListAdapter().getItemId(info.position); }
where "id" is the index of the item in the list. Now I want to get texview text with id = "myNr of this ListItem. Is there any way to get this text?
android listview adapter
Ripei
source share