findviewbyid简化

This commit is contained in:
huangzhuanghua
2017-01-16 12:28:15 +08:00
parent dd0f475944
commit 0ca70316dc
45 changed files with 163 additions and 263 deletions

View File

@ -31,9 +31,9 @@ import com.gh.gamecenter.listener.OnCallBackListener;
import com.gh.gamecenter.manager.SystemBarTintManager;
import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig;
import java.lang.reflect.Field;
import java.util.ArrayList;
import butterknife.ButterKnife;
import de.greenrobot.event.EventBus;
public class BaseActivity extends Activity implements OnCallBackListener {
@ -70,6 +70,8 @@ public class BaseActivity extends Activity implements OnCallBackListener {
setContentView(contentView);
ButterKnife.bind(this);
int actionbar_height = getSharedPreferences(Config.PREFERENCE,
Context.MODE_PRIVATE).getInt("actionbar_height",
DisplayUtils.dip2px(getApplicationContext(), 48));
@ -86,25 +88,6 @@ public class BaseActivity extends Activity implements OnCallBackListener {
finish();
}
});
//简化findViewById
try {
Class<?> clazz = this.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
int id = Utils.getId(field.getName());
if (id != -1) {
Utils.log("reflect name = " + field.getName());
field.setAccessible(true);
Class<?> fieldType = field.getType();
Object injectedValue = fieldType.cast(findViewById(id));
field.set(this, injectedValue);
field.setAccessible(false);
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
protected SystemBarTintManager getTintManager() {
@ -220,4 +203,5 @@ public class BaseActivity extends Activity implements OnCallBackListener {
public void loadEmpty() {
}
}