SHARE
TWEET

ListView

a guest Jan 14th, 2020 87 in 2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.masscode.utsmobileprogramming;
  2.  
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.AdapterView;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.ListView;
  8. import android.widget.TextView;
  9.  
  10. import androidx.appcompat.app.AppCompatActivity;
  11.  
  12. public class ListviewActivity extends AppCompatActivity {
  13.     TextView seleksi;
  14.     String[] pilihan = new String[]{"Merbabu", "Merapi", "Lawu",
  15.             "Rinjani", "Sumbing", "Sindoro",
  16.             "Krakatau", "Selat Sunda", "Selat Bali",
  17.             "Selat Malaka", "Kalimantan", "Sulawesi", "Jawa"};
  18.  
  19.     @Override
  20.     public void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_listview);
  23.         ListView listView = findViewById(R.id.list);
  24.         seleksi = findViewById(R.id.yangDipilih);
  25.  
  26.         ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, pilihan);
  27.         listView.setAdapter(adapter);
  28.         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  29.             @Override
  30.             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  31.                 seleksi.setText(pilihan[i]);
  32.             }
  33.         });
  34.     }
  35. }
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