1

Possible Duplicate:
How to add a button to PreferenceScreen

I want to add custom view at the bottom of the preference activity and also want to implement onClick of the views added in the screen? When i try to add view using layout inflator in preference screen it is always place at top of the preference view. But I want to show my view at bottom of the preference screen.

Below is the code snippets for adding layout in preference activity.

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.bottom_preference, null, true);
RelativeLayout.LayoutParams rl=new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,android.widget.RelativeLayout.LayoutParams.MATCH_PARENT);
rl.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
addContentView(view,rl);
Community
  • 1
  • 1
Silvans Solanki
  • 1,267
  • 1
  • 14
  • 27

1 Answers1

1

try this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    RelativeLayout parent = new RelativeLayout(this);

    Button button = new Button(this);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) generateLayoutParams(null);
    params.setMargins(35, 35, 0, 0);
    params.addRule(RelativeLayout.ALIGN_BOTTOM);
    button.setLayoutParams(params);

    parent.addView(button);

    setContentView(rl);
}
Heysem Katibi
  • 1,808
  • 2
  • 14
  • 29