Scroll layout in webview android - android

I am using web view in my application. web layout contains long layout so when i select on last edit text web view gets scroll but last edit text is not displaying focused because of it is hide from input soft keyboard . i want to show last edit text in visible view of web layout. any suggestion?
Xml
<com.salesgyani.android.pos.activities.ScrollWebView
xmlns:android="schemas.android.com/apk/res/android";
android:id="#+id/m_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true" />
and JAVA
public class ScrollWebView extends WebView {
public ScrollWebView(Context context) {
super(context);
}
public ScrollWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
public boolean onTouchEvent(MotionEvent event){
requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(event);
}
}

Related

What is correct way to make custom view based on EditText?

What is correct way to extend EditText?
The problem is following:
I have empty application from template with two EditText:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="one"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="two"/>
</LinearLayout>
It works fine:
Then I create my custom view from EditText:
public class CuteEditText extends EditText {
public CuteEditText(Context context) {
this(context, null);
}
public CuteEditText(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CuteEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// some special initialization will be here
}
}
And when I change EditText to my CuteEditText, interface works incorrectly:
The problem is not only with view ot UI. If I type something in first EditText and than touch the second one, nohing happens: input will continue in first.
The same behaviour if I inherite CuteEditText from AppCompatEditText.
What is wrong?
Sources for experiment are available at https://github.com/tseglevskiy/EditTextExperiment
Your construtors are broken. This is how it should look:
public class CuteEditText extends EditText {
public CuteEditText(Context context) {
super(context);
}
public CuteEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CuteEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
You don't need the third constructor overload. The first one is for creating the view programmatically and the second one is for creating the view from xml. Those two should be enough for most cases.
public class CuteEditText extends EditText {
public CuteEditText(Context context) {
this(context, null);
}
public CuteEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
}

Is there any way to make Linearlayout having children not clickable android?

I have a linearyLayout having several linearlayout and some views.
I want to make the whole layout not clickable.
this is the the first part of the linearlayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/selector_timetable_row"
android:orientation="vertical">
I first did inflating
View view = layoutInflater.inflate(~~, above layout);
And I did
view.setClickable(false);
but it is still clickable
listener to the layout still fires when i touch the layout.
You can disable touch event propagation with custom view like below:
public class CustomLinearLayout extends LinearLayout {
public CustomLinearLayout(Context context) {
super(context);
}
public CustomLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return false;
}
}
Use like this:
<{Here is package name}.CustomLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/selector_timetable_row"
android:orientation="vertical">

Customized Scrollable EditText in Scrollview Makes the Scrollview Jumps

I want to have a EditText in a scrollview and this EditText needs to be scrollable. So I made a customized one as follow:
public class myEditText extends EditText {
public myEditText(Context context) {
super(context);
}
public myEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public myEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
this.getParent().requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(ev);
}
}
This EditText has only one problem, that is when the text gets really long, the Scrollview containing it jumps for some reason. This makes me unable to edit text after a certain length. Is anyone know why that happens?
I think I solved it.
The issue was when there is a cursor in the EditText, the bringPointIntoView(int offset) method will make EditText scroll to the position where the cursor is at, so that the cursor will be in your sight and you can edit the text. Usually that's how it works, but when the EditText is in a ScrollView, instead of scroll the EditText, it makes the ScrollView scrolls as well. That's the reason I saw the ScrollView jumps.
The solution is simply override the bringPointIntoView method.
So if anyone wants to use a scrollable EditText in a ScrollView, I think this may help:
public class myEditText extends EditText {
public myEditText(Context context) {
super(context);
}
public myEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public myEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
this.getParent().requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(ev);
}
#Override
public boolean bringPointIntoView(int offset) {
return false;
}
}

Advantage of Button over TextView with Selector

I was looking at the documentation for the Button widget and noticed that it is a subclass of TextView. Is there any real difference between a Button and a TextView if I use the same selector drawable on both. In other words, I already am using TextViews with selectors for my app's "buttons", but is there anything to be gained from using the Button class instead?
No, there's essentially no difference between TextView and Button. Button just comes styled as a button out of the box.
Here is the source for Button from API 19.
#RemoteView
public class Button extends TextView {
public Button(Context context) {
this(context, null);
}
public Button(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.buttonStyle);
}
public Button(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(Button.class.getName());
}
#Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(Button.class.getName());
}
}

Android TimePicker (Wheel Style) not responding correctly to flick gestures inside ScrollView

I have a dialog box that contains a Scrollview, which contains a layout with two TimePickers.
The timepickers are the newer style ones, what's in ICS.
The problem is that they seem to fight for focus when you change the time by dragging the wheel, or flicking it. It will change the time just a little, and then the layout will scroll instead.
Any ideas?
Thanks in advance.
I had the same problem when using the Holo theme, and here is where I found the solution: https://groups.google.com/forum/?fromgroups#!topic/android-developers/FkSfJI6dH8w
You must implement your custom DatePicker or TimePicker and override the following method:
#Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
{
ViewParent p = getParent();
if (p != null)
p.requestDisallowInterceptTouchEvent(true);
}
return false;
}
Because the link from Klemens Zleptnig is broken, here is a complete example. This fix helps with the scroll of a TabLayout too btw. I excluded the area around the big numbers in the top of the TimePicker because they don't need the scroll event anyway.
xml:
<com.name.app.MyTimePicker
android:id="#+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>
java:
public class MyTimePicker extends TimePicker {
public MyTimePicker(Context context) {
super(context);
}
//This is the important constructor
public MyTimePicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTimePicker(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MyTimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
//Excluding the top of the view
if(ev.getY() < getHeight()/3.3F)
return false;
ViewParent p = getParent();
if (p != null)
p.requestDisallowInterceptTouchEvent(true);
}
return false;
}
}

Categories

Resources