Created
February 3, 2017 08:33
-
-
Save erlangparasu/0c422b3fb8acd4ee311142534d21f400 to your computer and use it in GitHub Desktop.
android, scrollview, scroll, view, focus
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
// ... | |
/* Scroll to a view */ | |
View view = errorViews.get(0); | |
View parent = mSvContent; | |
View parentTemp; | |
int y = 0; | |
for (; ; ) { | |
parentTemp = (View) view.getParent(); | |
y += parentTemp.getTop(); | |
if (parent.equals(parentTemp)) { | |
break; | |
} | |
view = parentTemp; | |
} | |
final int Y = y; | |
AlertDialog.Builder builder = new AlertDialog.Builder(this); | |
AlertDialog alertDialog = builder.setTitle(errorMessages.get(0)) | |
.setCancelable(false) | |
.setIcon(R.drawable.ic_info_black_24dp) | |
.setPositiveButton("ok", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
mSvContent.smoothScrollTo(0, Y); | |
errorViews.get(0).setFocusableInTouchMode(true); | |
errorViews.get(0).requestFocus(); | |
dialog.dismiss(); | |
} | |
}) | |
.create(); | |
alertDialog.show(); | |
// ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment