Advertisement
Guest User

Untitled

a guest
Apr 5th, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package hk.dvach.myapplication;
  2.  
  3. import android.content.DialogInterface;
  4. import android.support.v7.app.ActionBarActivity;
  5. import android.os.Bundle;
  6. import android.view.Gravity;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.LinearLayout;
  12.  
  13.  
  14. public class MainActivity extends ActionBarActivity {
  15.     public View.OnClickListener cll= new View.OnClickListener(){
  16.  
  17.         public void onClick(View  view){ view.setVisibility(View.GONE);};
  18.     };
  19.     int i=0;
  20.     public void addclick(View v){
  21.  
  22.         LinearLayout llo =(LinearLayout)findViewById(R.id.llo);
  23.         LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(100,100);
  24.         int btnGravity = Gravity.LEFT;
  25.         lParams.gravity = btnGravity;
  26.  
  27.         Button btnNew = new Button(llo.getContext());
  28.  
  29.         btnNew.setText("" + i++);
  30.         btnNew.setClickable(true);
  31.         btnNew.setOnClickListener(cll);
  32.  
  33.         llo.addView(btnNew, lParams);
  34.  
  35.     }
  36.     @Override
  37.     protected void onCreate(Bundle savedInstanceState) {
  38.         super.onCreate(savedInstanceState);
  39.         setContentView(R.layout.activity_main);
  40.     }
  41.  
  42.     @Override
  43.     public boolean onCreateOptionsMenu(Menu menu) {
  44.         // Inflate the menu; this adds items to the action bar if it is present.
  45.         getMenuInflater().inflate(R.menu.menu_main, menu);
  46.         return true;
  47.     }
  48.  
  49.     @Override
  50.     public boolean onOptionsItemSelected(MenuItem item) {
  51.         // Handle action bar item clicks here. The action bar will
  52.         // automatically handle clicks on the Home/Up button, so long
  53.         // as you specify a parent activity in AndroidManifest.xml.
  54.         int id = item.getItemId();
  55.  
  56.         //noinspection SimplifiableIfStatement
  57.         if (id == R.id.action_settings) {
  58.             return true;
  59.         }
  60.  
  61.         return super.onOptionsItemSelected(item);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement