inviteButton.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.ic_launcher)); inviteButton.setOnClickListener(new OnClickListener() {
Button b=new Button(context); b.setId(<some number>); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // do stuff here } });
View inflaterLayout; LinearLayout myLayout = (LinearLayout)findViewById(R.id.linearLayout2); while (counter < 5) { inflaterLayout = LayoutInflater.from(getBaseContext()).inflate(R.layout.newplayerlayout, null); myLayout.addView(inflaterLayout); Button testButton = (Button) myLayout.findViewById(R.id.button2); testButton.setId(testButtonArray[counter]); ((TextView) myLayout.findViewById(R.id.textView1)).setId(testTextArray[counter]); testButton.setOnClickListener(btnhandler); // Click Listener here counter++; }
buttonList = new ArrayList<Button>(); for (int i=0;i<5;i++){ Button button = new Button(getApplicationContext()); button.setOnClickListener(mThisButtonListener); button.setId(i); button.setTag(i); myLayout.addView(button); buttonList.add(button); }
if (items.size() > 0) { for (int i = 0; i < items.size(); i++) { View template = inflate(getContext(), R.layout.views_custom_list_item, null); template.setBackgroundDrawable(getProperBackgroundDrawable(i, items.size() - 1)); TextView text = (TextView)template.findViewById(R.id.custom_list_text); text.setText(items.get(i)); Button button = (Button)template.findViewById(R.id.custom_list_button); button.setId(i); button.setBackgroundDrawable(backgroundButton); button.setOnClickListener(callListener); addView(template); } }
buttonList = new ArrayList<Button>(); for (int i=0;i<5;i++){ Button button = new Button(getApplicationContext()); button.setOnClickListener(customListenner); button.setId(i); button.setTag(i); myLayout.addView(button); buttonList.add(button); }
public class InflateExActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { LinearLayout lLayout; Button b = null; super.onCreate(savedInstanceState); setContentView(R.layout.main); for(int i=0;i<3;i++){ final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); b = (Button) inflater.inflate(R.layout.buttons, null); b.setId(i); lLayout = (LinearLayout) findViewById(R.id.layout1); lLayout.addView(b); b.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(InflateExActivity.this, "Button Clicked :"+v.getId(), Toast.LENGTH_LONG).show(); } }); } }
View inflaterLayout; LinearLayout myLayout = (LinearLayout)findViewById(R.id.linearLayout2); while (counter < 5) { inflaterLayout = LayoutInflater.from(getBaseContext()).inflate(R.layout.newplayerlayout, null); myLayout.addView(inflaterLayout); Button testButton = (Button) myLayout.findViewById(R.id.button2); testButton.setId(testButtonArray[counter]); ((TextView) myLayout.findViewById(R.id.textView1)).setId(testTextArray[counter]); testButton.setOnClickListener(new View.OnClickListener() { int select = counter; @Override public void onClick(View v) { ((TextView) findViewById(testTextArray[select])).setText("Hi!"); } }); counter++; }
btn1.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v)
button1.setId(1); button2.setId(2); button1.setOnClickListener( new OnClickListener() { public void onClick(View v) { int id = v.getId(); button2.setOnClickListener( new OnClickListener() { public void onClick(View v) { int id = v.getId();
buttonList = new ArrayList<Button>(); for (int i=0;i<2;i++){ Button button = new Button(getApplicationContext()); button.setOnClickListener(customListenner); button.setAnimation(anim); button.setId(i); button.setTag(i); myLayout.addView(button); buttonList.add(button); }
Button charts = (Button) question.findViewById(R.id.chartsButton); charts.setId(pos); charts.setOnClickListener(chartsListener); TableRow tr = (TableRow) question; TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
public View getView(int position, final View convertView, ViewGroup parent) { Button btn = convertView; if (btn == null) { btn = new Button(mContext); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(mContext, Main.class) intent .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent); } }); btn.setLayoutParams(new GridView.LayoutParams(350, 65)); btn.setPadding(8, 8, 8, 8); btn.setWidth(LayoutParams.WRAP_CONTENT); } // set some text or do something ... return btn; }
Button charts = (Button) question.findViewById(R.id.chartsButton); charts.setId(pos); charts.setOnClickListener(chartsListener); TableRow tr = (TableRow) question; TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
Button charts = (Button) question.findViewById(R.id.chartsButton); charts.setId(pos); charts.setOnClickListener(chartsListener); TableRow tr = (TableRow) question; TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
Button b1 = new Button(context); b1.setId(1); b1.setOnClickListenr(new MyAction()); Button b2 = new Button(context); b2.setId(2); b2.setOnClickListener(new MyAction());
btn.setOnClickListener(new View.OnClickListener() {
Button charts = (Button) question.findViewById(R.id.chartsButton); charts.setId(pos); charts.setOnClickListener(chartsListener); TableRow tr = (TableRow) question; TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
public View getView(int position, View convertView, ViewGroup parent) { Button b; if (convertView == null) { b = new Button(mContext); b.setLayoutParams(new GridView.LayoutParams(parent.getWidth() / (Game.cols), parent.getHeight() / (Game.rows + 1))); //b.setHeight(Game.gv.getMeasuredHeight() / Game.rows); // This code from below SHOULDNT need to be done if the view already exists // Im also assuming that the drawable WILL NOT change, if it does, the 2 // lines below may move outside this if statement Drawable d = new BitmapDrawable(Game.splittedBitmaps[position]); b.setBackground(d); b.setId(position); b.setTag("Image_" + position); b.setOnClickListener(Game.s); Game.buttons[position] = b; } else { b = (Button) convertView; } return b; }
public View getView(int position, View convertView, ViewGroup parent) { Button btn; if (convertView == null) { // if it's not recycled, initialize some // attributes btn = new Button (mContext); btn.setLayoutParams(new GridView.LayoutParams(190, 190)); btn.setPadding(1, 1, 1, 1); } else { btn = (Button) convertView; } // btn.setText(filesnames[position]); // filenames is an array of // strings //btn.setTextColor (Color.WHITE); // btn.setBackgroundResource (R.drawable.sample_2); // btn.setBackgroundColor (Color.BLACK); btn.setHighlightColor(Color.GREEN); btn.setId(position); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Handle the click here } }); return btn; }