Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androiindians.listview.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ListView Example"
android:gravity="center" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listviewex" />
</LinearLayout>
MainActivity.java
package androiindians.listview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
ListView listView;
String[]Course={"Android","Java","Salesforce","PHP"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView= (ListView) findViewById(R.id.listviewex);
//custom layout array from java
ArrayAdapter arrayAdapter=new ArrayAdapter(getApplicationContext(),
R.layout.custom,Course);
listView.setAdapter(arrayAdapter);
}
}