本文實例講述了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程序設計有所幫助。