CustDialog用法 SimpleAdapter 用法
来源:互联网 发布:纵横公路造价软件 编辑:程序博客网 时间:2024/04/29 08:49
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import com.example.alertdialogtest3.R;import android.os.Bundle;import android.app.Activity;import android.app.Dialog;import android.content.Context;import android.util.Log;import android.view.KeyEvent;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.widget.AdapterView;import android.widget.Button;import android.widget.ListView;import android.widget.SimpleAdapter;public class FrameActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Log.d("TEST___"," FrameActivity ");}/* 退出 */public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {exitDialog(FrameActivity.this, R.layout.exitdialog);}return false;}/* 自定义的Dialog */public Dialog exitDialog(final Context context, int layoutId) {final Dialog dialog = new Dialog(context, R.style.NoTitleDialog);View layout = LayoutInflater.from(context).inflate(layoutId, null);///* 确定 */Button confirmbutton = (Button) layout.findViewById(R.id.confirmdialog);confirmbutton.setOnClickListener(new OnClickListener() {public void onClick(View v) {System.exit(0);}});/* 取消 */Button cancelbutton = (Button) layout.findViewById(R.id.canceldialog);cancelbutton.setOnClickListener(new OnClickListener() {public void onClick(View v) {dialog.dismiss();}});// add:ListView listView1=(ListView) layout.findViewById(R.id.listView1);SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.dialog_listitem, new String[] {"type" }, new int[] { R.id.textView1 }); listView1.setAdapter(adapter);listView1.setOnItemClickListener(new OnItemClickListener_Ex());dialog.setContentView(layout);dialog.show();return dialog;}private List<Map<String, Object>> getData() { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>(); list=new ArrayList<Map<String, Object>>();map = new HashMap<String, Object>();map.put("type", "1 test");list.add(map);map = new HashMap<String, Object>();map.put("type", "2 test");list.add(map);map = new HashMap<String, Object>();map.put("type", "3 test");list.add(map); return list;}class OnItemClickListener_Ex implements ListView.OnItemClickListener {@Overridepublic void onItemClick(AdapterView<?> arg0, View v, int position,long item_line_id) {Log.d("TEST___"," @@is "+ position);}}}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginLeft="17dp" android:layout_marginTop="135dp" android:layout_toRightOf="@+id/textView1" > </ListView></RelativeLayout>
dialog_listitem.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="30dp" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /></LinearLayout>
exitdialog.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginLeft="17dp" android:layout_marginTop="135dp" android:layout_toRightOf="@+id/textView1" > </ListView></RelativeLayout>
0 0
- CustDialog用法 SimpleAdapter 用法
- SimpleAdapter用法
- SimpleAdapter用法疑问测试
- SimpleAdapter适配器用法
- SimpleAdapter的用法
- SimpleAdapter的用法
- Android-SimpleAdapter用法学习
- SimpleAdapter用法代码 自己标的用法
- Android开发SimpleAdapter的简单用法
- ListView 与 SimpleAdapter的简单用法
- ListView和SimpleAdapter的入门用法
- android ListView适配器之SimpleAdapter的用法
- SimpleAdapter及Toast的简单用法
- 安卓开发中SimpleAdapter的用法
- Android-简单适配器SimpleAdapter的用法
- [Android] Adapter:SimpleAdapter SimpleCursorAdapter ArrayAdapter 与ListView的用法
- 安卓开发Android之SimpleAdapter ArrayAdapter 用法总结
- Android进步之路四:SimpleAdapter类的具体用法
- Linux下多线程程序崩溃时如何提取出所有线程的函数调用栈(一)
- 大整数加法初稿--未完成
- 对于看书的一些感悟(编程思想)
- 在framework中添加方法后new不过
- i2c信号的ACK与NACK
- CustDialog用法 SimpleAdapter 用法
- android2.2应用开发之IccCard(sim卡或USIM卡)
- objective-c 自定义类
- 总线和共同沟
- C++ call matlab on <mac + xcode >
- adb 命令实践篇
- redhat linux配置本地yum源
- ios 得到当前使用wifi的名称
- 内存篇之堆的错误释放