Android常用方法

多线程:
thread,RunThread
MyThread t=new MyThread
t.start();




Thread thread=new Thread(new MyRunThread)
thread.stsrt();


Adapter:


自定义:
public class NewsTestAdapter extends BaseAdapter{
public int getCount() {

return this.mlist==null?0:this.mlist.size();
}


@Override
public NewsContext getItem(int position) {
return this.mlist.get(position);
}


@Override
public long getItemId(int position) {
return position;
}


public View getView(int position, View converView, ViewGroup arg2){
}
}


Fragment:


public class FirstFragement extends Fragment{


@Override
public void onAttach(Activity activity) {
mActivity=activity;
super.onAttach(activity);
}


@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view=inflater.inflate(R.layout.first_fragement, null);
view.findViewById(R.id.fragebtn).setOnClickListener(this);
view.findViewById(R.id.changebtn).setOnClickListener(this);
image=(ImageView) view.findViewById(R.id.frageimage);
return view;
}
}


设置Fragment:


FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragmentContainer, new FirstFragement(), "one");
ft.commit();


FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
Fragment hf=getSupportFragmentManager().findFragmentByTag("one");
ft.hide(hf);
ft.commit();




用Fragment实现的滑屏:
public class NewsFragmentAdapter extends FragmentPagerAdapter {
private ArrayList<Fragment> mlist;



public NewsFragmentAdapter(FragmentManager fm, ArrayList<Fragment> mlist) {
super(fm);
this.mlist = mlist;
}






public NewsFragmentAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}






@Override
public Fragment getItem(int position) {
// TODO Auto-generated method stub
return this.mlist.get(position);
}


@Override
public int getCount() {
// TODO Auto-generated method stub
return this.mlist.size();
}




}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值