android - Getting Text from TextView nested in ListView via LongClick -
I have is populated with stories from Skyueliti dB according to user input with text in a list view that written. My code is:
cursor cursor = mDbHelper.searchDb ((query = null query.toString (): "@@@@"); If (cursor == zero) {} else {string}] = new string [] {COLUMN-1, COLUMN-2, COLUMN-3}; For Int [] = new int [] (Rt.TexView1, RID.TextView2, R.Id.TexView3); Simple cursor adapter cursor adapter 1 = new simple cursor adapter (this, R.Let Search results, cursor, from, to); MListView.setAdapter (cursorAdapter1); RegisterForContextMenu (mListView);
And I ContextMenu
@Override public boolean (MenuItem item) onContextItemSelected {AdapterView.AdapterContextMenuInfo information = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo (); Int menuItemindex = item.getitim id (); String [] menuItems = {"Option-1", "Option-2"}; String MenuEutamName = MenuItem [menuItemIndax]; TextView Text View4 = (TextView) findViewById (R.id.textView1); String Text = Text View4.getText (); If (menuItemIndex == 0) {Toast.makeText (getApplicationContext (), text, Toast.LENGTH_LONG) .show (); } Back true; }
I am trying to get the text of the item (in the text list view list) long click in the toast through the string "text" but it is always clicked on the list Should the item be clicked without returning the text of the items that can be seen before? I can not understand where I am wrong in the code?
"itemprop =" text ">
After you try adding a lonfClick listener to your ListView, and clicking on the contents of the item Clicked Something like in your case,:
yourListView.setOnItemLongClickListener (New OnItemLongClickListener () {public boolean onItemLongClick (AdapterView & lt; & gt; arg0, views, Int position, long id) { string text =. ((TextView) View) .getText () toString (); Toast.makeText (getApplicationContext (), text, Toast.LENGTH_SHORT) .show (); return true;}});
I hope this helps !!
Comments
Post a Comment