Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello i used spanabletring for all item list when Click On every item list it run if click on every word go to search activity but when use OnItemLong click after spanableString my app force close
what should i do? please help me

C#
private boolean init(View view) {
       ViewHolder ocHolder =  (ViewHolder)view.getTag();
       TextView ocTextTitle =(TextView)ocHolder.txtTitle;
       String definition =ocTextTitle.getText().toString().trim();
      ocTextTitle.setMovementMethod(LinkMovementMethod.getInstance());
        ocTextTitle.setText(definition, TextView.BufferType.SPANNABLE);
     Spannable spans = (Spannable) ocTextTitle.getText();
        BreakIterator iterator = BreakIterator.getWordInstance(Locale.US);
        iterator.setText(definition);
        int start = iterator.first();

        for (int end = iterator.next(); end != BreakIterator.DONE; start = end, end = iterator
                .next()) {
            String possibleWord = definition.substring(start, end);
            if (Character.isLetterOrDigit(possibleWord.charAt(0))) {
                ClickableSpan clickSpan = getClickableSpan(possibleWord);
                spans.setSpan(clickSpan, start, end,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            }
        }
       return true;
   }

    private boolean onItemLongClick(ListView listview) {

        listview.setOnItemLongClickListener(ChildList.this);
        return true;  
    }

    private ClickableSpan getClickableSpan(final String word) {
        return new ClickableSpan() {
            final String mWord;
            {
                mWord = word;

            }

            @Override
            public void onClick(View widget) {
                Intent intent = new Intent ( ChildList.this, loginTwo.class );
                intent.putExtra ( "TextBox",mWord);
                startActivity(intent);

                Log.d("tapped on:", mWord);
                Toast.makeText(widget.getContext(), mWord, Toast.LENGTH_SHORT)
                        .show();

            }
Posted
Updated 9-Nov-14 17:44pm
v2
Comments
Sinisa Hajnal 10-Nov-14 2:15am    
Look at the app log and see which line fails and what is the error. Post it here. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900