首页 > 移动平台 > 详细

android零碎学习记录之 TextSwithcer

时间:2015-03-01 17:10:58      阅读:262      评论:0      收藏:0      [点我收藏+]
  1. TextSwitcher 翻译“文本转换开关”,顾名思义:该转换开关是转换TextView的。开关,意思很明确,必定只有2个文本,一个展示(即“开”),一个隐藏(即“关”)。

2. 简单示例:

   java代码:

View rootView = inflater.inflate(R.layout.fragment_main, container,
					false);
			final TextSwitcher switcher = (TextSwitcher)rootView.findViewById(R.id.textswitcher);
			
			final TextView firsttext = new TextView(PlaceholderFragment.this.getActivity());
			firsttext.setId(123);
			final TextView secondtext = new TextView(PlaceholderFragment.this.getActivity());
			secondtext.setId(456);
			
			switcher.addView(firsttext, 0);
			switcher.addView(secondtext,1);
			Button button = (Button)rootView.findViewById(R.id.myButton);
			
			button.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					
					int xx = switcher.getCurrentView().getId();
					Log.i("textswitcher的当前view的id是",""+xx);
					if(xx==123){
						switcher.setText("123123213");
					}else if(xx == 456){
						switcher.setText("9999993");
					}
					
				}
			});
			
			return rootView;
3.定义布局文件如下:(定义一个textswitcher即可)

<TextSwitcher android:id="@+id/textswitcher"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

         >

        

    </TextSwitcher>


android零碎学习记录之 TextSwithcer

原文:http://2240844.blog.51cto.com/2230844/1616297

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!