2013-05-24 2 views
0

여러 줄이있는 textView 있고 특정 줄을 클릭하고 클릭 한 줄 인쇄 할 것입니다. 나는 이것을 만들었지 만 TwxtView (모든 줄)에 모든 문자열을 제공합니다.해당 줄에 clcik있는 TextView있는 특정 줄을 얻는 방법

<TextView 
    android:id="@+id/board" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:maxLines="100" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

자바 코드 :

TextView board; 

public void onCreate(Bundle savedInstanceState) 
{ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.edite); 

     board=(TextView) findViewById(R.id.board); 

     board.setOnClickListener(new OnClickListener() 
     { 
      public void onClick(View v) 
      { 
       System.out.println(((TextView)v).getText().toString()); 
      } 
     }); 
+0

그리고 당신의 질문은 무엇인가 작동을 위해 @neevek? – B770

+0

클릭 한 라인을 어떻게 얻을 수 있습니까? – Salman

+1

이것은 불가능하거나 어떤 종류의 해킹이 잘 수행 할 수 있다고 생각하지 않습니다. 이를 수행하기 위해 사용자 정의보기를 구현하고 클릭 된 좌표를 추적하고 선을 좌표와 연관시켜야합니다. – neevek

답변

0

덕분에 자신의 힌트

는이 방법

board=(TextView) findViewById(R.id.board); 


    board.setOnTouchListener(new OnTouchListener() 
    { 
     public boolean onTouch(View v, MotionEvent event) 
     { 
      // TODO Auto-generated method stub 

      Layout layout = ((TextView) v).getLayout(); 
      int x = (int)event.getX(); 
      int y = (int)event.getY(); 
      if (layout!=null) 
      { 
       x=0; 
       int characterOffset = 0 ;  
       String Selectedline="";   


       String s= board.getText().toString(); 
       char [] k=s.toCharArray(); 

       int line = layout.getLineForVertical(y); 
       for(x=5;k[characterOffset]!='\n';) 
       { 
         characterOffset = layout.getOffsetForHorizontal(line,x); 
         Selectedline=Selectedline+Character.toString(k[characterOffset]); 
         System.out.println("x is: "+x+"Character is: "+k[characterOffset]+"Selectedline is: "+Selectedline); 
         x=x+8; 
       } 

      } 

      return true; 
     } 
    }); 
관련 문제