G'day、
さまざまなテキスト値が設定されたListViewがあります。長い間コンテキストメニューを押して開いたときに、あなたが長押ししたListItem。これまでのところ私は、「コピー」オプションをポップアップ表示するコンテキストメニューを持っている:アイテムのIDがクリックされました - Android ContextMenu
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
//this was following another question but I don't know what to do with it
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
long selectedId = info.id;
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context, menu);
}
public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId())
{
case R.id.copy:
//used to be in a function but wasn't sure about views
//yes I know it's depreciated but it works ;)
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
TextView clicked = (TextView)this.findViewById(???);
clipboard.setText(clicked.getText());
Context context = getApplicationContext();
Toast copied = Toast.makeText(context, "Story copied to clipboard.", Toast.LENGTH_LONG);
copied.show();
return true;
default:
return super.onContextItemSelected(item);
}
}
おかげ
問題がありますか? –
@Chirag私はどこに置くべきかわからない???です。長押ししたアイテムのIDを渡すことができたら、ちょうど... findViewById(id); – ProfSmiles