0

Is it somehow possible to achieve that? In example: we have listView with 20 items, every item has some text. User want to select half of ending text from item 1. and the half of another item text (same behaviour like in webView or selectable textView). Did someone think about that feature? Where should I search the solution?

This topic will be updated when solution will be found.

ps. I know you will say "show us code first". I do not have it yet.

deadfish
  • 11,996
  • 12
  • 87
  • 136
  • http://stackoverflow.com/questions/22809130/to-select-text-from-multiple-textviews is related to this question. That is impossible with standard components, you need to rethink the UX. – Viktor Yakunin Mar 17 '15 at 12:57

4 Answers4

1

In your istview on item click listener code like this

lv.setOnItemClickListener(new OnItemClickListener(){
 @Override 
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3)
{


            // TODO Auto-generated method stub
            TextView tv;
            String text_from_tv, finalText;
             tv= (TextView) view.findViewById(R.id.textview_id);
             text_from_tv = tv.getText();
            if(!firstPartSelected)
              finalText += text_from_tv.substring(0,text_from_tv.length()/2);
            else
             finalText += text_from_tv.substring(text_from_tv.length()/2,text_from_tv.length());

           //Save this finalText String to any string array and use those values

       }
    });

and that string array contains the second halfs of the selected word, if it helpful up vote the answer!!

Kanth K
  • 128
  • 13
0

In your list_item.xml for your list view. You will want to set,android:textIsSelectable="true" and make android:clickable="true" for that same item.

0

I won't give any code, just how I would do it :

boolean firstPartSelected false;
String finalText ="";

// ListView Definition

// OnItemClickListener
OnItemClick(...){
    if(!firstPartSelected)
        finalText += TextFromItem.substring(0,TextFromItem.length()/2)
    else
        finalText += TextFromItem.substring(TextFromItem.length()/2,TextFromItem.length())
}

This is not some real code, just an idea of how to implement it. Is that what you wanted ?

Jejefcgb
  • 390
  • 3
  • 14
0

Try handle OnFocusChangeListener for your EditText, when focus will be change, color selected text in EditText using spans (Android: Coloring part of a string using TextView.setText()?). If you have large count of EditText you can use view.setTag(etNumber) and (Integer)view.getTag() for each EditText and use this information while concat output string in loop (look for more info Android - get children inside a View?)

P.S. EditText is inheritor of TextView, what yo can do with TextView you will can do with EditText

Community
  • 1
  • 1