You need to convert the resource identifier that you are returning from R.drawable.dividerto a Drawable, ala object:
import android.content.res.Resources;
...
public void onCreate(Bundle savedInstanceState) {
...
Resources res = this.getResources();
LinearLayout layout = new LinearLayout(this);
layout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE | LinearLayout.SHOW_DIVIDER_BEGINNING | LinearLayout.SHOW_DIVIDER_END);
layout.setDividerDrawable(res.getDrawable(R.drawable.divider));
...
}
...
It is assumed that you have a file named "divider.jpg" (or similar) in your resource directory.
source
share