import java.util.zip.Inflater;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Context context;
Button btn;
int flag;
// Context context = this;
// @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
flag=1;
// LayoutInflater inflater = (LayoutInflater)context.getSystemService
// (Context.LAYOUT_INFLATER_SERVICE);
//
// LinearLayout layout = (LinearLayout) inflater.inflate(R.id.lilili, null);
//
// Button btn = new Button(this);
// btn.setPadding(7, 3, 7, 5);
// btn.setTextColor(Color.BLUE);
//
// layout.addView(btn);
//
// setContentView(R.layout.activity_main);
LinearLayout linear = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT);
linear.setBackgroundColor(Color.GREEN);
RelativeLayout text = (RelativeLayout)View.inflate(this, R.layout.activity_main, null);
btn = new Button(this);
btn.setLayoutParams(params);
btn.setText("Hello");
btn.setText("Hi");
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "Button Clicked", 1).show();
if(flag == 1) {
btn.setText("Hello");
flag=0;
}
else {
btn.setText("hi");
flag=1;
}
}
});
linear.addView(text, params);
linear.addView(btn,params);
setContentView(linear);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
댓글 없음:
댓글 쓰기
국정원의 댓글 공작을 지탄합니다.