SHARE
TWEET

Untitled

Tulus97 May 23rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainActivity extends AppCompatActivity {
  2.     private ListView listView;
  3.     ArrayAdapter<String> adapter;
  4.     ArrayList<HashMap<String, String>> itemListView;
  5.  
  6.     @Override
  7.     protected void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.activity_main);
  10.  
  11.         listView= (ListView) findViewById(R.id.listview);
  12.  
  13.         final String[] judul = {
  14.                 "1. Apple",
  15.                 "2. Samsung",
  16.                 "3. Oppo",
  17.                 "4. Vivo",
  18.                 "5. Xiaomi",
  19.                 "6. LG",
  20.                 "7. Nexia",
  21.                 "8. Mito",
  22.                 "9. Asus",
  23.                 "10. Nokia",
  24.                 "dan seterusnya"
  25.         };
  26.  
  27.         adapter = new ArrayAdapter<String>(this, R.layout.item_view,
  28.                 R.id.isi, judul);
  29.         listView.setAdapter(adapter);
  30.         ivenKlik();
  31.     }
  32.  
  33.     private void ivenKlik() {
  34.         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  35.             @Override
  36.             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  37.                 String data =listView.getItemAtPosition(position).toString();
  38.                 Intent intent= new Intent(this, Detail.class);
  39.                 //Detail.class akan error dikarenakan kita belum membuat Detail class
  40.                 intent.putExtra("input", data);
  41.                 startActivity(intent);
  42.             }
  43.         });
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top