package cn.zengfansheng.news163Sort;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
private TextView tv_out;
private TextView tv_in;
private TextView tv_nows;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_out = (TextView) this.findViewById(R.id.news_international);
tv_in = (TextView) this.findViewById(R.id.news_inland);
tv_nows = (TextView) this.findViewById(R.id.news_nows);
tv_out.setOnClickListener(this);
tv_in.setOnClickListener(this);
tv_nows.setOnClickListener(this);
//让程序你运行起来,就自动替换国际新闻中的内容
FragmentManager fragmentManager = this.getFragmentManager();
FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
beginTransaction.replace(R.id.ll_content, new OutFragment());
beginTransaction.commit();
}
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
FragmentManager fragmentManager = this.getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
switch (v.getId()) {
case R.id.news_international:
fragmentTransaction.replace(R.id.ll_content, new OutFragment());
// 替换ll_content中的内容,用new OutFragment()替换
break;
case R.id.news_inland:
fragmentTransaction.replace(R.id.ll_content, new InFragment());
break;
case R.id.news_nows:
fragmentTransaction.replace(R.id.ll_content, new NowsFragment());
break;
}
fragmentTransaction.commit();
}
}