I am learning RecycleView now and just wondering how to display the data in the same way like Listview.
public class MainActivity extends AppCompatActivity {
String[] mobileArray = {"Android","IPhone","WindowsMobile",
"Blackberry","WebOS","Ubuntu","Windows7","Max OS X"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, mobileArray);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplication(), mobileArray[i],
Toast.LENGTH_LONG).show();
}
});
}
}
The above coding is just to display the Array in ListView using ArrayAdapter. When clicking on the item, it will Toast that position value.
So the same thing for Recycleview, I saw some examples online that are with very many lines of coding or even separate files. Is Recycleview really need so many lines of coding to display a simple array like this?
String[] mobileArray = {"Android","IPhone","WindowsMobile",
"Blackberry","WebOS","Ubuntu","Windows7","Max OS X"};
Anyone can provide a simplest example to Display an Array in RecycleView with onItemClick then show that position in Toast? OR did I do it wrongly as Recycleview is used to do something more complex or just listview will do for my case?