感觉android做界面都是使用xml文件,动态完成相当繁琐。有没相关网上资料,主要是关于制作界面的。另外问个问题,我网上下载了一个代码,用eclipse添加进来。代码主要功能是制作一个文件选择对话框。MyFileManager是我的文件选择对话框类,继承于ListActivity,这个工程里成功实现了。
Intent intent = new Intent(Main.this, MyFileManager.class);
startActivityForResult(intent, 1);但是我自己创建了一个新工程,基本上如法炮制,但是为什么这个文件选择对话框是非模态的?也就是点击对话框后,对话框就消失了,这个是在哪里设置,需要设置什么?这个问题查了好久不知道原因。

解决方案 »

  1.   

    对话框里面是什么内容?如果是listview   那就从写他的onClickItemListener方法
      

  2.   


    是重写了这个函数,和demo是一样的,但DEMO的样子相当于模态对话框,而我写出来的点到后边对话框就消失了。
      

  3.   

    public class MyFileManager extends ListActivity {
    private List<String> items = null;
    private List<String> paths = null;
    private String rootPath = "/";
    private String curPath = "/";
    private TextView mPath; @Override
    protected void onCreate(Bundle icicle) {
    super.onCreate(icicle); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.fileselect);
    mPath = (TextView) findViewById(R.id.mPath);
    Button buttonConfirm = (Button) findViewById(R.id.buttonConfirm);
    buttonConfirm.setOnClickListener(new OnClickListener() { public void onClick(View v) {
    Intent data = new Intent(MyFileManager.this, MainAcivity.class);
    Bundle bundle = new Bundle();
    bundle.putString("file", curPath);
    data.putExtras(bundle);
    setResult(2, data);
    finish(); }
    });
    Button buttonCancle = (Button) findViewById(R.id.buttonCancle);
    buttonCancle.setOnClickListener(new OnClickListener() { public void onClick(View v) {
    finish();
    }
    });
    getFileDir(rootPath);
    } private void getFileDir(String filePath) {
    mPath.setText(filePath);
    Log.d("touch", String.valueOf(mPath.getText()));
    File f = new File(filePath);
    items = new ArrayList<String>();
    paths = new ArrayList<String>();
    if (!filePath.equals(rootPath)) {
    items.add("b1");
    paths.add(rootPath);
    items.add("b2");
    paths.add(f.getParent());
    }
    if (!f.exists()) {
    setListAdapter(new MyAdapter(this, items, paths));
    return;
    }
    File[] files = f.listFiles();
    if (files == null) {
    setListAdapter(new MyAdapter(this, items, paths));
    return;
    } for (int i = 0; i < files.length; i++) {
    File file = files[i];
    items.add(file.getName());
    paths.add(file.getPath());
    }
    setListAdapter(new MyAdapter(this, items, paths));
    } @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    File file = new File(paths.get(position));
    if (file.isDirectory()) {
    curPath = paths.get(position);
    getFileDir(paths.get(position));
    } else {
    curPath = paths.get(position);
    mPath.setText(paths.get(position));
    // openFile(file);
    }
    }
    }
      

  4.   

    public class Main extends Activity {
    Button btn; @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main); btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent intent = new Intent(Main.this, MyFileManager.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);    startActivityForResult(intent, 1);
    }
    }); } // @Override
    // public boolean onCreateOptionsMenu(Menu menu) {
    // getMenuInflater().inflate(R.menu.main, menu);
    // return true;
    // } @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (1 == requestCode) {
    Bundle bundle = null;
    if (data != null && (bundle = data.getExtras()) != null) {
    btn.setText("选择文件夹为:" + bundle.getString("file"));
    }
    }
    }
    }
      

  5.   

    初学者, 界面框架可以用droiddraw试试, 可视的UI编辑工具
      

  6.   

    楼主去这里看一下,可能会对你有帮助
    http://blog.csdn.net/ada168855/article/details/7772734
    还有就是楼主说:“感觉android做界面都是使用xml文件,动态完成相当繁琐。”。
    你有这种想法可能是因为你还没有适应android这种编写程序的模式,其实你要是理解了android的这种MVC模式,你就会感叹这种模式是如何之好。当然,如果楼主真的不想在xml中配置widget的话,也可以像java中一样,直接用代码来实现,楼主可以去这里看一下这个简单的例子:
    http://blog.csdn.net/ada168855/article/details/7791052