当前位置:编程学习 > wap >>

Android 普通View类里面的按钮怎么调用Activity里面的Dialog??

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布局的 大家帮帮帮哦 Android --------------------编程问答-------------------- 在这个acitivy里创建这个view,在View.OnClickListener的onClick()中直接调用showDialog(openfileDialogId)即可; --------------------编程问答--------------------
引用
在这个acitivy里创建这个view,在View.OnClickListener的onClick()中直接调用showDialog(openfileDialogId)即可;



能不能让他们独立 在Activity里面创建这个不可能的 这个人把控件单独写出来 哎 调用一个按钮的很困难 --------------------编程问答--------------------   木有人吗?? --------------------编程问答-------------------- 大神们呢??
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,