I codeD一个自己的适配器,通过一个ListView控件添加到我的ListActivity。 为什么我写一个自己的适配器的原因是,我不得不做出一些布局更改列表entrys。在我已经有了3 TextViews列表中的每一个条目。
I coded an own Adapter and added it to my ListActivity via an ListView. The reason why I wrote an own Adapter is, that i had to make some layout changes to the list-entrys. In every entry of the list i've got 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>
接下来的事情我所做的,是实现onListItemClick-了Methode。后来我实现了一个onListItemLongClick - 监听器具有以下code:
The next thing i did, was to implement a "onListItemClick-Methode". Afterwards i implemented a onListItemLongClick - Listener with the following code:
在活动我加入的onCreate:
in onCreate of the Activity i added:
registerForContextMenu(getListView());
然后我增加了以下梅索德:
then i added the following methode:
Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo){
AdapterView.AdapterContextMenuInfo info;
info = (AdapterView.AdapterContextMenuInfo) menuInfo;
long id = getListAdapter().getItemId(info.position);
}
其中,id为在列表中的项目的索引。 我现在想要得到与此列表项的id =myNr的texview的文本。 有没有办法得到这个文本?
where "id" is the index of the item in the list. I now want to get the Text of the texview with the id="myNr of this ListItem. Is there any way get this Text?
推荐答案
大家好,我发现另一种方式来设置ItemLongClickListener。因此,我还找到了一种方法来获取文本我展示。
Hey Guys I found another way to set an ItemLongClickListener. Therefore i also found a way to get the Text i am displaying.
ListView lv = getListView();
lv.setOnItemLongClickListener(new OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int row, long arg3) {
String[] tmp = (String[]) arg0.getItemAtPosition(row);
//tmp[0] ist the Text of the first TextView displayed by the clicked ListItem
return true;
}});
相关推荐
最新文章