Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 4.72 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to define the position of a alert dialog in view [closed]
  2. LayoutInflater inflater=getLayoutInflater();
  3. View view = inflater.inflate(R.layout.actionbarmain,null);
  4. view.setMinimumWidth(200);
  5. view.setMinimumHeight(400);
  6.  
  7. AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
  8. alertDialog.setView(view);
  9. alertDialog.show();
  10.        
  11. public class EditPropertyActivity extends Activity {
  12.  
  13.     /** Called when the activity is first created. */
  14.     // @Override
  15.     /*
  16.      * (non-Javadoc)
  17.      *
  18.      * @see android.app.Activity#onCreate(android.os.Bundle)
  19.      */
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  23.         setContentView(R.layout.dialog);
  24.         setTitle("");
  25.         TextView propName = (TextView) findViewById(R.id.tv_propName);          
  26.  
  27.         propName.setText(getIntent().getExtras().getString("prop_label"));
  28.  
  29.         final EditText ed_propValue = (EditText) findViewById(R.id.ed_propValue);
  30.         ed_propValue.setText(value);
  31.         if (tagName.equals("timeout")) {
  32.             ed_propValue.setInputType(InputType.TYPE_CLASS_NUMBER);
  33.         }
  34.         Button btn_save = (Button) findViewById(R.id.btn_save);
  35.         btn_save.setOnClickListener(new View.OnClickListener() {
  36.         //onclick
  37.         }
  38.     }
  39.        
  40. <activity
  41.             android:name="EditPropertyActivity"
  42.             android:theme="@android:style/Theme.Dialog" >
  43.         </activity>
  44.        
  45. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  46.     android:layout_width="fill_parent"
  47.     android:layout_height="fill_parent"
  48.     android:orientation="vertical" >
  49.  
  50.     <TextView
  51.         android:id="@+id/tv_propName"
  52.         android:layout_width="200dip"
  53.         android:layout_height="wrap_content"
  54.         android:layout_gravity="center"
  55.         android:layout_marginBottom="10dip"
  56.         android:layout_marginLeft="15dip"
  57.         android:layout_marginRight="25dip"
  58.         android:layout_marginTop="10dip"
  59.         android:text="Medium Text"
  60.         android:textAppearance="?android:attr/textAppearanceMedium" />
  61.  
  62.     <EditText
  63.         android:id="@+id/ed_propValue"
  64.         android:layout_width="match_parent"
  65.         android:layout_height="wrap_content"
  66.         android:ems="10" >
  67.  
  68.         <requestFocus />
  69.     </EditText>
  70.  
  71.     <LinearLayout
  72.         android:layout_width="fill_parent"
  73.         android:layout_height="wrap_content"
  74.         android:layout_marginLeft="2dp"
  75.         android:layout_marginRight="2dp"
  76.         android:orientation="horizontal" >
  77.  
  78.         <Button
  79.             android:id="@+id/btn_save"
  80.             android:layout_width="0dip"
  81.             android:layout_height="wrap_content"
  82.             android:layout_weight="1"
  83.             android:text="@string/lbl_btn_save" />
  84.  
  85.         <Button
  86.             android:id="@+id/btn_cancel"
  87.             android:layout_width="0dip"
  88.             android:layout_height="wrap_content"
  89.             android:layout_weight="1"
  90.             android:text="@string/cancel" />
  91.     </LinearLayout>
  92.  
  93. </LinearLayout>
  94.        
  95. <?xml version="1.0" encoding="utf-8"?>
  96. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  97.     android:layout_width="fill_parent"
  98.     android:layout_height="fill_parent"
  99.     android:orientation="vertical" >
  100.  
  101.             <Button
  102.                 android:id="@+id/btn1"
  103.                 android:layout_width="wrap_content"
  104.                 android:layout_height="wrap_content"
  105.                 android:text="test" />
  106.             <Button
  107.                 android:id="@+id/btn2"
  108.                 android:layout_width="wrap_content"
  109.                 android:layout_height="wrap_content"
  110.                 android:text="test" />
  111.             <Button
  112.                 android:id="@+id/btn3"
  113.                 android:layout_width="wrap_content"
  114.                 android:layout_height="wrap_content"
  115.                 android:text="test" />
  116. </LinearLayout>
  117.        
  118. AlertDialog.Builder builder=new Builder(YourActivityName.this);
  119.                 LayoutInflater inflater=getLayoutInflater();
  120.                 View view=inflater.inflate(R.layout.testxml, null);
  121.                 builder.setView(view);
  122.                 builder.setTitle("New Project");
  123.                 builder.setMessage("knknknknknmknknknk");
  124.                 builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
  125.  
  126.                     @Override
  127.                     public void onClick(DialogInterface dialog, int which) {
  128.  
  129.                     }
  130.                 });
  131.                 builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
  132.  
  133.                     @Override
  134.                     public void onClick(DialogInterface dialog, int which) {
  135.  
  136.                     }
  137.                 });
  138.                 builder.create();
  139.                 builder.show();