Reputation:
I've tried so many posts here in StackOverflow
but with no luck. My requirement is very simple. I have a listView
. When scrolling the listView
, I want to detect the Fading Edge
, i.e. I want to show a Log massage when the fading edge will be visible. How can I detect the Fading Edge
?
*UPDATE: I found the solution. Here is my Solution.*
STEP 1: First I extended the ListView as shown below
ManipulateList.java
public class ManipulateList extends ListView {
public ManipulateList(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public ManipulateList(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public ManipulateList(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX,
boolean clampedY) {
// TODO Auto-generated method stub
Log.d("***", "Over Scrolling: Fading Edge NOW Visible");
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}
}
Here you can See, I've overridden the onOverScrolled
method to do my Own Task here.
Step 2: "activity_main.xml" declaration with my modified listview
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<com.example.customlist.ManipulateList
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</com.example.customlist.ManipulateList>
</RelativeLayout>
STEP 3: My main activity's onCreate Method shown Below
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ManipulateList listView = (ManipulateList) findViewById(R.id.listView1);
String[] swName = new String[] {"a", "b","c",
"d", "e","f",
"g", "h","i",
"j", "k","l",
"m", "n","o",
"p", "q","r",
"s", "t","u",
"v", "w","x",
"y","z","a","b",
"c","d","e","f"
};
ArrayAdapter<String> swGAA = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, swName);
listView.setAdapter(swGAA);
}
STEP 4: ENJOY!
Upvotes: 1
Views: 707
Reputation: 9299
The "Fading Edge" is referred to as an "Overscroll" effect.
Look at the onOverScroll() method.
EDIT: It isn't called OverScroll. It is called EdgeEffect.
Upvotes: 3