Comments (4)
不知道你指的更好的解决方式是哪方面呢? @lvtanxi
from viewfinder.
`package com.znn.injectview;
import android.app.Activity;
import android.app.Dialog;
import android.support.annotation.IdRes;
import android.view.View;
/**
- User: 吕勇
- Date: 2016-07-27
- Time: 13:08
- Description:
*/
public class Finder {
public static T findView(Object tag, View rootView, @idres int viewId) {
if (null != rootView) {
return (T) rootView.findViewById(viewId);
} else if (tag instanceof Activity) {
return (T) ((Activity) tag).findViewById(viewId);
} else if (tag instanceof View) {
return (T) ((View) tag).findViewById(viewId);
} else if (tag instanceof Dialog) {
return (T) ((Dialog) tag).findViewById(viewId);
}
return null;
}
}`
from viewfinder.
这个地方我参考了 ButterKnife
项目的设计,使用 Provider
接口来把 findViewById()
这样的方法抽象出来,Activity 的实现版本参考 ActivityProvider
。
这样子,在执行 inject()
根据不同的重载方法(Activity、View 等),提供不同的 Provider
实现
from viewfinder.
PS. Markdown 语法中,代码块可以用三个点 ****
****** 来包裹起来, 一个点 **
是 行内代码片段
from viewfinder.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from viewfinder.