Activity类
public class OpenFileDemo extends Activity {
static private int openfileDialogId = 0;
private Vibrator m_iShakeHandle = null;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDialog(openfileDialogId);
}
@Override
protected Dialog onCreateDialog(int id) {
if(id==openfileDialogId){
Map<String, Integer> images = new HashMap<String, Integer>();
// 下面几句设置各文件类型的图标, 需要你先把图标添加到资源文件夹
images.put(OpenFileDialog.sRoot, R.drawable.filedialog_root); // 根目录图标
images.put(OpenFileDialog.sParent, R.drawable.filedialog_folder_up); //返回上一层的图标
images.put(OpenFileDialog.sFolder, R.drawable.filedialog_folder); //文件夹图标
images.put("wav", R.drawable.filedialog_wavfile); //wav文件图标
images.put(OpenFileDialog.sEmpty, R.drawable.filedialog_root);
Dialog dialog = OpenFileDialog.createDialog(id, this, "打开文件", new CallbackBundle() {
@Override
public void callback(Bundle bundle) {
String filepath = bundle.getString("path");
setTitle(filepath); // 把文件路径显示在标题上
}
},
".wav;",
images);
return dialog;
}
return null;
}
}
View类
[code]
m_iBrightSubBtn = this.AddButtonToLayout(getContext(), iLayoutView, "", buttona, iViewHeight/5, 0, 0);
m_iBrightSubBtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
m_iShakeHandle.vibrate(50);
}
});
[/code]
接的别人的项目 控件不是用XML布局的 大家帮帮帮哦
------解决方案--------------------
在这个acitivy里创建这个view,在View.OnClickListener的onClick()中直接调用showDialog(openfileDialogId)即可;
------解决方案--------------------
你在你想弹出dialog的控件设置个事件就能了撒
------解决方案--------------------
让它们独立的话,就把context作为一个参数,各个activity就在用的时候传进来。
这样就把dialog公用了,解耦合了