社区
Android
帖子详情
求这样的AlterDialog代码
csl312211865
2011-02-15 07:23:25
如题,代码。
...全文
135
6
打赏
收藏
求这样的AlterDialog代码
如题,代码。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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弹出的吧
金山卫士学习第一天源
代码
黑马程序员Android版金山卫士学习...7、
Alter
dialog
8、两种上下文 9、下载--FinalHttp 10、安装apk 11、应用程序的签名; 12、ListView gridView 数据适配 13、滚动的TextView 14、自定义组合控件 实现关闭自动更新;
Android 自定义
dialog
的实现
代码
Android 自定义
dialog
的实现
代码
搜索相关关键字网上一大堆实现,但是看完总觉得缺胳膊少腿,绕了不少...(网上文章要么少介绍第2点,要么是使用
Alter
Dialog
直接实现效果) 先看下效果,模仿微信风格的
dialog
: 允
安卓学习-
Alter
Dialog
的基本使用
alter
Dialog
Android 中
Alter
Dialog
使用
Android 中
Alter
Dialog
使用,
Alter
Dialog
的使用分为两种,一种是直接使用,一种是自己设计一个Layout,然后当做
Dialog
显示出来。 1、定义两个Button,一个用来显示
Alter
Dialog
,一个显示自定义的
Alter
Dialog
。 ...
Android
Alter
Dialog
常用对话框使用方法详解
关注微信号:javalearns...
Alter
Dialog
在Android开发中使用也比较频繁,本文就介绍了
Alter
Dialog
的几种对话框使用方式及
代码
解析。 使用Aler
Dialog
创建对话框 : Alert
Dialog
.Builder builder = new Alert
Dialog
.
Android
80,351
社区成员
91,288
社区内容
发帖
与我相关
我的任务
Android
移动平台 Android
复制链接
扫一扫
分享
社区描述
移动平台 Android
android
android-studio
androidx
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章