求这样的AlterDialog代码

csl312211865 2011-02-15 07:23:25



如题,代码。
...全文
135 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ArashmenZhu 2011-02-16
  • 打赏
  • 举报
回复
是Activity,但是要在AndroidManifest.xml
去把这个Activity的属性 theme=dialog
设置主题为dialog,他就自动生成那个页面
然后你在activity里面再去对ListView进行生成adapter就行了、
相当简单的,关键是--->在AndroidManifest.xml,去把这个Activity的属性 theme=dialog
csl312211865 2011-02-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hacker1125 的回复:]

是ListActivity
[/Quote]这个应该是AlertDialog吧?
hacker1125 2011-02-16
  • 打赏
  • 举报
回复
是ListActivity
筱周 2011-02-16
  • 打赏
  • 举报
回复
在书上找了个例子发你看看
应该是类似于这样的
ex05_11.java:

package org.example.ex05_11;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

public class ex05_11 extends ListActivity {

private List<String> items = null;
private List<String> paths = null;
private String rootPath = "/";
private TextView mPath;

/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

mPath = (TextView) findViewById(R.id.tv);
getFileDir(rootPath);

}

private void getFileDir(String filePath) {
// TODO Auto-generated method stub
mPath.setText(filePath);

items = new ArrayList<String>();
paths = new ArrayList<String>();
File f = new File(filePath);
File[] files = f.listFiles();

if (!filePath.equals(rootPath)) {
items.add("b1");
paths.add(rootPath);

items.add("b2");
paths.add(f.getParent());
}
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) {
// TODO Auto-generated method stub
File file = new File(paths.get(position));

if (file.canRead()) {
if (file.isDirectory()) {
getFileDir(paths.get(position));
} else {
openFile(file);
}
} else {
new AlertDialog.Builder(this).setTitle("Message").setMessage(
"权限不足!").setPositiveButton("OK",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}
}).show();

}

}

private void openFile(File f) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);

String type = getMIMEType(f);
intent.setDataAndType(Uri.fromFile(f), type);

startActivity(intent);
}

private String getMIMEType(File f) {
// TODO Auto-generated method stub
String type = "";
String fName = f.getName();
String end = fName.substring(fName.indexOf(".") + 1, fName.length())
.toLowerCase();

if (end.equals("m4a") || end.equals("mp3") || end.equals("mid")
|| end.equals("xmf") || end.equals("ogg") || end.equals("wav")) {
type = "audio";
} else if (end.equals("3gp") || end.equals("mp4")) {
type = "video";
} else if (end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp")) {
type = "image";
} else {
type = "*";
}

type += "/*";
return type;
}
}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>


MyAdapter.java:

package org.example.ex05_11;

import java.io.File;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {

private LayoutInflater mInflater;
// private Bitmap mIcon_one;
// private Bitmap mIcon_two;
// private Bitmap mIcon_three;
// private Bitmap mIcon_four;
private List<String> items;
private List<String> paths;

public MyAdapter(Context context, List<String> it, List<String> pa) {
// TODO Auto-generated constructor stub
mInflater = LayoutInflater.from(context);

items = it;
paths = pa;

// mIcon_one = BitmapFactory.decodeResource(context.getResources(),
// R.drawable.outofline);
// mIcon_two = BitmapFactory.decodeResource(context.getResources(),
// R.drawable.online);
// mIcon_three = BitmapFactory.decodeResource(context.getResources(),
// R.drawable.floder);
// mIcon_four = BitmapFactory.decodeResource(context.getResources(),
// R.drawable.icon);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub

ViewHolder holder;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.file_row, null);

holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
// holder.icon = (ImageView) convertView.findViewById(R.id.icon);

convertView.setTag(holder);

} else {
holder = (ViewHolder) convertView.getTag();
}

File f = new File(paths.get(position).toString());

if (items.get(position).toString().equals("b1")) {
holder.text.setText("Back to /");
// holder.icon.setImageBitmap(mIcon_one);
} else if (items.get(position).toString().equals("b2")) {
holder.text.setText("Back to ..");
// holder.icon.setImageBitmap(mIcon_two);
} else {
holder.text.setText(f.getName());
if (f.isDirectory()) {
// holder.icon.setImageBitmap(mIcon_three);
} else {
// holder.icon.setImageBitmap(mIcon_four);
}
}
return convertView;
}

private class ViewHolder {
TextView text;
// ImageView icon;
}

}


file_row.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

儿大不由爷 2011-02-16
  • 打赏
  • 举报
回复
这个是spinner弹出的吧

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧