在代码中新建Layout

1.声明一个layout

LinearLayout linearLayoutMain = new LinearLayout(this);
		linearLayoutMain.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

 

2.放入一个listview

ListView listView = new ListView(this);
listView.setFadingEdgeLength(0);
listView.setAdapter(openDialogAdp);
linearLayoutMain.addView(listView);

 

3.用一个AlertDialog来响应弹出

editDialog = new AlertDialog.Builder(this).setView(linearLayoutMain)
				.create();
		editDialog.setCanceledOnTouchOutside(false);
		
	
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// arg2 is the position you clicked
				String number = extracts.get(arg2).getNumber();
				Intent data = new Intent();
				data.putExtra(CONTACT_DETAILS_RESULT_NUMBER, number);
				setResult(PICK_CONTACT_REQUEST, data);
				finish();

				editDialog.cancel();
			}
		});

		editDialog.show();

 

 

你可能感兴趣的:(layout)