Created
August 10, 2017 04:01
-
-
Save Nazmul56/aa8d088f63996e3f450d9c748256cf80 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.example.hp.animationonrecyclerview; | |
import android.os.Handler; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
public class MainActivity extends AppCompatActivity { | |
private LinearLayoutManager linearLayoutManager; | |
RecyclerView rView; | |
List<RecyclerViewItem> allItems; | |
List<RecyclerViewItem> testAllItems; | |
RecylerViewAdapterDemo recylerViewAdapterDemo; | |
Handler handler; | |
String title[] = {"Shaon", "Ashiq", "Najmul", "Nadim", "Jafor"}; | |
String subTitle[] = {"ShaonSubTitle", "AshiqSubTitle", | |
"NajmulSubTitle", "NadimSubTitle", "JaforSubTitle"}; | |
Timer timer; | |
TimerTask timerTask; | |
int n = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
handler = new Handler(); | |
} | |
private List<RecyclerViewItem> getItemList() { | |
List<RecyclerViewItem> allItems = new ArrayList<RecyclerViewItem😠); | |
String title[] = {"Shaon", "Ashiq", "Najmul", "Nadim", "Jafor"}; | |
String subTitle[] = {"ShaonSubTitle", "AshiqSubTitle", | |
"NajmulSubTitle", "NadimSubTitle", "JaforSubTitle"}; | |
int image[] = {R.mipmap.man1,R.mipmap.man2, | |
R.mipmap.man3,R.mipmap.man4,R.mipmap.man5} ; | |
//, R.mipmap.recycler_circle_image | |
if(n == 5) | |
n = 0; | |
if(n < 5) { | |
allItems.add(new RecyclerViewItem(title[n], subTitle[n], image[n])); | |
} | |
return allItems; | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
startTimer(); | |
} | |
public void startTimer() { | |
timer = new Timer(); | |
initializeTimerTask(); | |
timer.schedule(timerTask, 0, 5000); // | |
} | |
public void initializeTimerTask() { | |
timerTask = new TimerTask() { | |
public void run() { | |
handler.post(new Runnable() { | |
public void run() { | |
List<RecyclerViewItem> rowListItem = getItemList(); | |
linearLayoutManager = new LinearLayoutManager(MainActivity.this); | |
rView = (RecyclerView) findViewById(R.id.recycler_view); | |
rView.setLayoutManager(linearLayoutManager); | |
recylerViewAdapterDemo = new RecylerViewAdapterDemo(MainActivity.this, rowListItem); | |
rView.setAdapter(recylerViewAdapterDemo); | |
n++; | |
} | |
}); | |
} | |
}; | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
if (timer != null) { | |
timer.cancel(); | |
timer = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment