This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//定义泛型接口 | |
public interface HttpCallBack<T> { | |
public void onSuccess(T result); | |
public void onFail(Throwable throwable); | |
} | |
//定义父类子类model | |
public class ChildModel extends ParentModel { | |
String result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//滑动视图 | |
public class MyScrollView extends ViewGroup { | |
Context context; | |
Scroller scroller=null; | |
VelocityTracker tracker=null; | |
//判断点击还是滑动 | |
int touchSlop=0; | |
//滑动速度临界值 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//fragment页签使用方法 | |
//初始化时候将缓存的所有fragment全部隐藏 | |
List<Fragment> fragments=getSupportFragmentManager().getFragments(); | |
if(fragments!=null) { | |
for(int i=0;i<fragments.size();i++) { | |
getSupportFragmentManager().beginTransaction().hide(fragments.get(i)).commit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//viewPager中加载frament方法 | |
//查找是不是已经保存过fragment,优先使用保存过的fragment | |
if(savedInstanceState!=null) { | |
fragment1=(MyGridViewFragment) getChildFragmentManager().getFragment(savedInstanceState, "first"); | |
if((MyGridViewFragment) getChildFragmentManager().getFragment(savedInstanceState, "first")==null) { | |
fragment1=MyGridViewFragment.getInstance(1); | |
} | |
else { | |
fragment1=(MyGridViewFragment) getChildFragmentManager().getFragment(savedInstanceState, "first"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//viewpager中同时包含image跟surfaceview的情况处理 | |
//给viewPager中的View添加id,便于后续查找 | |
for(int i=0;i<multi_media.size();i++) { | |
if (multi_media.get(i).gettype().endsWith("0")) { | |
ImageView imageView=new ImageView(this); | |
imageView.setImageResource(R.drawable.ic_launcher); | |
bitmapUtils.display(imageView, multi_media.get(i).getDescription_url(), config); | |
views.add(imageView); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//动态刷新fragment的方法 | |
//将FragmentTransaction中的fragment全部清除 | |
public void addFragment() { | |
if(fragment_list != null){ | |
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
for(Fragment f: fragment_list){ | |
ft.remove(f); | |
} | |
ft.commitAllowingStateLoss(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 循环检测activity是否初始化完毕 | |
starnum_seekbar.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
// TODO Auto-generated method stub | |
if (null != getWindow().getDecorView().getWindowToken()) { | |
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
View undoView = inflater.inflate( | |
R.layout.view_seekbarhint2, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
db.beginTransaction(); | |
String[][] lifes = {{"potato", "tomato", "apple"}, {"rat", "cat", "dog"}}; | |
SQLiteStatement stmt = db.compileStatement("insert into life values(?,?)"); | |
for(int i=0;i<lifes[0].length;i++){ | |
stmt.clearBindings(); | |
stmt.bindString(1, lifes[0][i]); | |
stmt.bindString(1, lifes[1][i]); | |
stmt.executeInsert(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 切换为全屏 | |
private void setFullScreen() { | |
if (Build.VERSION.SDK_INT >= 9) { | |
setRequestedOrientation(6); | |
} else { | |
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | |
} | |
getWindow().addFlags(1024); | |
mActionBar.hide(); | |
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//类似数组[行, 列] | |
//表示起始位置为0,占据2行 | |
GridLayout.Spec rowSpec=GridLayout.spec(0, 2, GridLayout.UNDEFINED); | |
//表示起始位置为1,占据1列 | |
GridLayout.Spec columnSpec=GridLayout.spec(i, 1, GridLayout.UNDEFINED); | |
GridLayout.LayoutParams params=new GridLayout.LayoutParams(rowSpec, columnSpec); | |
gridlayout.addView(view, params); | |
此外xml中也要预先定好多少行多少列 |
OlderNewer