Git Product home page Git Product logo

Comments (4)

bruce3x avatar bruce3x commented on August 10, 2024

不知道你指的更好的解决方式是哪方面呢? @lvtanxi

from viewfinder.

lvtanxi avatar lvtanxi commented on August 10, 2024

`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.

bruce3x avatar bruce3x commented on August 10, 2024

这个地方我参考了 ButterKnife 项目的设计,使用 Provider 接口来把 findViewById() 这样的方法抽象出来,Activity 的实现版本参考 ActivityProvider
这样子,在执行 inject() 根据不同的重载方法(Activity、View 等),提供不同的 Provider 实现

from viewfinder.

bruce3x avatar bruce3x commented on August 10, 2024

PS. Markdown 语法中,代码块可以用三个点 ********** 来包裹起来, 一个点 ** 是 行内代码片段

from viewfinder.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.