I want to dynamically create a LinearLayout.
How do I set it to display in my AlertDialog?
I've seen examples where the layout was created via XML and inflated to show, but I do not want to create XML layouts when I can do it dynamically.
I'm restricted to API 16 = Android 4.1.2
This is a button on my activity...
public void TestOnClick() {
Button test_button = (Button) findViewById(R.id.button_test);
test_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinearLayout layout = new LinearLayout(v.getContext());
//Create a TextView to add to layout
TextView textview = new TextView(v.getContext());
textview.setText("My Test");
layout.addView(textview);
//Add abunch of other items to the layout
//blah blah blah
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setView(layout);
builder.setNeutralButton("Done", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}

to apply dialog theme to an activity,simply modify the element in the AndroidManifest.xml file by adding the android:theme attribute like this:
Doing so will make the activity appear as a dialog..
Further,if you need to hide the activity title from displaying..add this line in OnCreate method of your activity
thats all,upvote if this helps you ... Visit This Page