Created
December 13, 2016 06:43
-
-
Save dharmakshetri/d5614cd8fe959ea003aa55982058b8cc 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
public class MainActivity extends AppCompatActivity { | |
public final String TAG="RXANDROID"; | |
RecyclerView recyclerListView; | |
MyAdapter myAdapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// creating layout | |
recyclerListView=(RecyclerView) findViewById(R.id.recylerview_list); | |
recyclerListView.setLayoutManager(new LinearLayoutManager(this)); | |
myAdapter= new MyAdapter(this); | |
recyclerListView.setAdapter(myAdapter); | |
// creating observales | |
creatingObserable(); | |
} | |
// method that added list of names | |
public List<String> getNameList(){ | |
List<String> list= new ArrayList<>(); | |
list.add("Bob"); | |
list.add("Dave"); | |
list.add("Mike"); | |
list.add("John"); | |
list.add("Jannie"); | |
list.add("Ammy"); | |
return list; | |
} | |
// creating Obserables | |
private void creatingObserable() { | |
final Observable <List<String>> listObserable= Observable.just(getNameList()); | |
listObserable.subscribe(new Observer<List<String>>() { | |
@Override | |
public void onCompleted() { | |
Log.d(TAG, "onCompleted()"); | |
} | |
@Override | |
public void onError(Throwable e) { | |
Log.d(TAG, "onError()",e); | |
} | |
@Override | |
public void onNext(List<String> data) { | |
myAdapter.setData(data); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment