CustDialog用法 SimpleAdapter 用法

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 {




	@Override
	protected 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 {


		@Override
		public 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值