package com.example.codelayoutexample;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class CodeLayoutExample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutParams params1 = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
TextView text = new TextView(this);
text.setText("I am TextView");
text.setLayoutParams(params1);
EditText edit = new EditText(this);
edit.setHint("This is EditView....");
edit.setLayoutParams(params1);
Button button = new Button(this);
button.setText("Click me");
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast makeText = Toast.makeText(v.getContext(), "Clicked", Toast.LENGTH_SHORT);
makeText.show();
}
});
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(10, 10, 10, 10);
layout.addView(text);
layout.addView(edit);
layout.addView(button);
setContentView(layout);
}
}