Skip to content

Instantly share code, notes, and snippets.

@talobin
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talobin/11025737 to your computer and use it in GitHub Desktop.
Save talobin/11025737 to your computer and use it in GitHub Desktop.
Android:
Edittext Autocapitalize, add this to properties of Edittext:
android:inputType="textCapSentences"
ListView context Menu:
//*********************************
//Inside onCreate
//Get a hold of the list
ListView list = (ListView) findViewById(R.id.list);
//Register and handle longclick
registerForContextMenu(list);
list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
list.showContextMenuForChild(arg0);
return false;
}
});
//*********************************
//Somewhere inside the class:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, v.getId(), 0, "copy");
//to get position
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle(acmi.position);
AdapterView.AdapterContextMenuInfo info = null;
try {
info = (AdapterView.AdapterContextMenuInfo) menuInfo;
} catch (ClassCastException e) {
Log.e("", "bad menuInfo", e);
return;
}
//if (model.get(info.position).msgName != null)
// menu.setHeaderTitle(model.get(info.position).msgName);
//else
// menu.setHeaderTitle(model.get(info.position).msgNumber);
menu.setHeaderTitle("Test");
String[] menuItems = { getResources().getString(R.string.delete) };
for (int i = 0; i < menuItems.length; i++) {
menu.add(Menu.NONE, i, i, menuItems[i]);
// }
}}//
@SuppressLint({ "NewApi", "ServiceCast" })
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle().equals("copy")){
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
String textTocopy ="Test";//adapter.getItem(index-1).title;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("simple text",textTocopy);
clipboard.setPrimaryClip(clip);}
else{
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(textTocopy);
}
}
else {return false;}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment