Created
May 7, 2015 12:33
-
-
Save plastiv/5143896623f7ecc606bc to your computer and use it in GitHub Desktop.
SegmentedEditText
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SegmentedEditText is horizontal linear layout contains 6 edit texts | |
public class SegmentedEditText extends LinearLayout { | |
public SegmentedEditText(Context context) { | |
super(context); | |
LayoutInflater inflater = LayoutInflater.from(context); | |
for (int i = 0; i < 6; i++) { | |
// have to do next: | |
EditText editText = (EditText) inflater.inflate(R.layout.partial_segmented_edittext, this, false); | |
addView(editText); | |
// instead of this: | |
// code below crashes at the runtime, because inflate method returns LinearLayout not EditText | |
// I don't need reference for the LinearLayout, since I already have it. It is provided to the method. | |
// What I need is reference for the newly inflated EditText to avoid finding it by Id later | |
EditText editText = (EditText) inflater.inflate(R.layout.partial_segmented_edittext, this, true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dude, you can't do this. Just do a simple layout for this :
segmented_edit_text_layout.xml
Then on your Activity you set it as your content view :
OR on Fragment