-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ephraim Muhia <emuhia@ona.io>
- Loading branch information
Ephraim Muhia
committed
Feb 2, 2018
1 parent
c20d607
commit 500412c
Showing
6 changed files
with
87 additions
and
16 deletions.
There are no files selected for viewing
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
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
55 changes: 55 additions & 0 deletions
55
opensrp-path/src/main/java/org/smartregister/path/view/CustomHeightSpinner.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.smartregister.path.view; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.util.Log; | ||
import android.widget.Spinner; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* Created by keyman on 2/2/18. | ||
*/ | ||
|
||
@SuppressLint("AppCompatCustomView") | ||
public class CustomHeightSpinner extends Spinner { | ||
private static final String TAG = CustomHeightSpinner.class.getName(); | ||
|
||
public CustomHeightSpinner(Context context) { | ||
super(context); | ||
} | ||
|
||
public CustomHeightSpinner(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public CustomHeightSpinner(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public void updateHeight(final int height, final int itemCount) { | ||
try { | ||
final Field popup = Spinner.class.getDeclaredField("mPopup"); | ||
popup.setAccessible(true); | ||
|
||
// Get private mPopup member variable and try cast to ListPopupWindow | ||
final android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(this); | ||
|
||
// Set popupWindow height to max - 40dp | ||
this.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
int heightToUse = height; | ||
if (heightToUse == -1) { | ||
heightToUse = CustomHeightSpinner.this.getHeight(); | ||
} | ||
popupWindow.setHeight(heightToUse * itemCount); | ||
popup.setAccessible(false); | ||
} | ||
}); | ||
} catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) { | ||
Log.e(TAG, e.getMessage(), e); | ||
} | ||
} | ||
} |
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
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
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