本文实例讲述了Android上使用jspf插件框架的方法。分享给大家供大家参考。具体如下:
jspf (Java Simple Plugin Framework) 是一个插件框架,集成了很多 IoC 框架的概念在里面。
package de.jspfdemo; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.impl.PluginManagerFactory; import net.xeoh.plugins.base.util.uri.ClassURI; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import de.jspfdemo.plugins.CoolPlugin; import de.jspfdemo.plugins.impl.CoolPluginImpl; public class JSPFDemo extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Loading and adding plugins via class uri PluginManager pm = PluginManagerFactory.createPluginManager(); pm.addPluginsFrom(new ClassURI(CoolPluginImpl.class).toURI()); // Getting the CoolPlugin CoolPlugin plugin = pm.getPlugin(CoolPluginImpl.class); // Setting the text of a TextView with the help of the CoolPlugin TextView textView = (TextView) findViewById(R.id.textView); textView.setText(plugin.sayHello()); } }
希望本文所述对大家的Android程序设计有所帮助。