2014-06-24 2 views
0

내 응용 프로그램에 텍스트 변환기가 있습니다. 모든 것이 효과적입니다. 내 텍스트가 전환 중이지만 텍스트 전환기의 텍스트를 클릭하면 다른 활동을 열려고합니다. 어떻게 안드로이드에서 이것을 얻을 수 있습니까 ?? 사전 :다른 활동을 열 수 있도록 TextSwitcher에서 텍스트를 클릭 할 수있게 만드는 방법은 무엇입니까?

텍스트 스위처의 코드가에서

감사합니다 ...

public class Course1 extends Activity 
{ 
    private TextSwitcher mSwitcher; 
    Button btnNext; 

    // Array of String to Show In TextSwitcher 
    String textToShow[]={"Main HeadLine","Your Message","New In Technology","New Articles","Business News","What IS New"}; 
    int messageCount=textToShow.length; 
    // to keep current Index of text 
    int currentIndex=-1; 



    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
       super.onCreate(savedInstanceState); 

       setContentView(R.layout.course1);      

       // get The references 
       btnNext=(Button)findViewById(R.id.buttonNext); 
       mSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher); 

       // Set the ViewFactory of the TextSwitcher that will create TextView object when asked 
       mSwitcher.setFactory(new ViewFactory() { 

        public View makeView() { 
         // TODO Auto-generated method stub 
         // create new textView and set the properties like clolr, size etc 
         TextView myText = new TextView(Course1.this); 
         myText.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); 
         myText.setTextSize(36); 
         myText.setTextColor(Color.BLUE); 
         return myText; 
        } 
       }); 

       // Declare the in and out animations and initialize them 
       Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left); 
       Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right); 

       // set the animation type of textSwitcher 
       mSwitcher.setInAnimation(in); 
       mSwitcher.setOutAnimation(out); 




       // ClickListener for NEXT button 
       // When clicked on Button TextSwitcher will switch between texts 
       // The current Text will go OUT and next text will come in with specified animation 
       btnNext.setOnClickListener(new View.OnClickListener() { 

        public void onClick(View v) { 
         // TODO Auto-generated method stub 
         currentIndex++; 
         // If index reaches maximum reset it 
         if(currentIndex==messageCount) 
          currentIndex=0; 
         mSwitcher.setText(textToShow[currentIndex]); 
        } 
       }); 

    } 
} 

답변

1

mSwitcher.setOnClickListener(new View.OnClickListener() { 

        public void onClick(View v) { 
         // TODO Auto-generated method stub 
         if(currentIndex==0){ 
         Intent i = new Intent(getApplicationContext(),NextActivity.class); 
         startActivity(i); 
         } else if(currentIndex==1){ 
         Intent i = new Intent(getApplicationContext(),NextActivity.class); 
         startActivity(i); 
         } 
        } 
       }); 
+0

나는 텍스트에 따라 활동을 열고 싶다 ... 나는 모든 텍스트에 대해 동일한 활동을 열지 않으려한다. 모든 텍스트에 대해 동일한 활동을 열 것이라고 생각 하는가? –

+0

다음 onClick 메서드에서 텍스트를 가져 와서 원하는 특정 활동을 엽니 다 –

+0

나는 현재 색인 값을 얻음으로써 그것을했습니다 :) –

1

내가 :) thanxx : shylendra의 도움으로 그것을 해결하려고

여기 내 최종 코드입니다 ....

btnNext.setOnClickListener(new View.OnClickListener() { 

    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     currentIndex++; 
     // If index reaches maximum reset it 
     if(currentIndex==messageCount) 
      currentIndex=0; 
     mSwitcher.setText(textToShow[currentIndex]); 
    } 
}); 


mSwitcher.setOnClickListener(new View.OnClickListener() { 

    public void onClick(View v) { 
     if(currentIndex==0) 
     { 
     Intent i = new Intent(getApplicationContext(),lastyear.class); 
     startActivity(i); 
    }else if(currentIndex==1) 
    { 
     Intent i = new Intent(getApplicationContext(),MainActivity.class); 
     startActivity(i); 

    } 

    } 
});