Reputation: 159
I am developing a new Android app, i have listed out the records. Now need to show the particular record while clicking on the corresponding button.
Can somebody help me to share how to create buttons dynamically and assign record id into it?
Upvotes: 0
Views: 80
Reputation: 1478
Why can't you list it out in a ListView?? If you can do so, you can dynamically add items easily, and get the click function from listItem's onclick listner
ListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// Write your click action here
}
});
Upvotes: 0
Reputation: 445
you can do as below r LinearLayout btnLayout = new LinearLayout(this);
Button send = new Button(this);
send.setText("Send");
send.setTextColor(Color.WHITE);
btnLayout.addView(send);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Write yout code here
}
}
Upvotes: 0
Reputation: 416
RelativeLayout relativeLayout =(RelativeLayout)findViewById(R.id.relative);
Button button2 = new Button(this);
button2.setId(recordId);
relativeLayout.addView(button2);
Upvotes: 0
Reputation: 206
Button btn=new Button(this);
btn.setId(you record id here);
then add this button to your view
Upvotes: 1