Adapters-App List

 Output:



Activity main xml

 <ListView
        android:id="@+id/listview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


Main Java

public class MainActivity extends AppCompatActivity {
    ListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 1- AdapterView: ListView
        listview = findViewById(R.id.listview);

        // 2- Data Source: String Array
        String[] countries = {"USA", "Germany", "Saudi Arabia","France"};


        // 3- Adapter: acts as a bridge between the
        //            'data source' and the 'AdapterView'
        ArrayAdapter<String> adapter = new ArrayAdapter<>(
                this,
                android.R.layout.simple_list_item_1,
                countries
        );

        // Link Listview with the Adapter
        listview.setAdapter(adapter);

    }
}

Comments

Popular posts from this blog

Widgets

List View : Planet Application

Recycler View: MarketApp