私は現在、拡張する主な活動をしていますListActivity
ListAdapter
データベースからのエントリでアクティビティを膨らませています。TextViews
コンテキストメニューとして動作する膨張したエントリがありますが、クリックすると、選択した ListView 内のいずれかから値を取得できるようにしたいと考えていますOnListItemClick listener
。
問題は、長押しでコンテキスト メニューがアクティブになったときにOnItemClickListener
登録されずListView
、通常の短いクリックと同じように値を取得できないことです。onListItemClick
をView
クリックすると が表示されますが、 は表示さonContextItemSelected
れず、 のみが表示されますMenuItem
。
public class EntryActivity extends ListActivity
{
String currentItemName;
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
//The Value i need is this: currentItemName,
//and i need it to register when a list item is clicked
TextView curName =(TextView)v.findViewById(R.id.txtName) ;
currentItemName = curName.getText().toString();
}
//I need to use the String obtained from the click in the context menu
//to call a method, but a long click makes the onContextItemSelected
//be called, so onItemClickListener is never called, and i cant get the string
@Override
public boolean onContextItemSelected(MenuItem item )
{
switch(item.getItemId())
{
case ADD_ONE:
methodCalled(currentItemName);
break;
}
}
//I am inflating the list with a DataAdapter and a ListAdapter
private void refresh()
{
//create an array the size of the cursor(one item per row)
InventoryItem[] items = new InventoryItem[c.getCount()];
//create and set the DataAdaptor with the array of inventory items, to the
//inventoryList layout
da = new DataAdapter(this, R.layout.inventorylist, items);
setListAdapter(da);
}
}
クリックしたビューを contextMenu リスナーで使用できるようにする方法はありますか? それとも、これについて間違った方法で行っていますか?