Advertisement
ZazoTazo

ListView

Jul 31st, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package com.rcc2.www.listview;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.widget.ListView;
  6.  
  7. import java.util.ArrayList;
  8.  
  9. public class ListViewActivity extends AppCompatActivity {
  10.  
  11.     @Override
  12.     protected void onCreate(Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_listview);
  15.  
  16.         ArrayList<Mobile> arrayList = new ArrayList<>();
  17.  
  18.         Mobile m1 = new Mobile();
  19.         m1.setName("Nokia");
  20.         m1.setPrice(6400);
  21.         m1.setImage(R.drawable.ic_launcher_background);
  22.         arrayList.add(m1);
  23.  
  24.         Mobile m2 = new Mobile();
  25.         m2.setName("Huawei");
  26.         m2.setPrice(5700);
  27.         m2.setImage(R.drawable.ic_launcher_background);
  28.         arrayList.add(m2);
  29.  
  30.         Mobile m3 = new Mobile();
  31.         m3.setName("Sony");
  32.         m3.setPrice(8400);
  33.         m3.setImage(R.drawable.ic_launcher_background);
  34.         arrayList.add(m3);
  35.  
  36.         Mobile m4 = new Mobile();
  37.         m4.setName("LG");
  38.         m4.setPrice(4200);
  39.         m4.setImage(R.drawable.ic_launcher_background);
  40.         arrayList.add(m4);
  41.  
  42.         ListView listView = findViewById(R.id.listView);
  43.         MobileAdapter mobileAdapter = new MobileAdapter(ListViewActivity.this, R.layout.row_design, arrayList);
  44.         listView.setAdapter(mobileAdapter);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement