Answers for "android studio listview"

1

android studio listview example

// XML code :
//in activity_main.xml
<ListView
    android:id="@+id/simpleListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>


// custom_item.xml :
<LinearLayout 
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:orientation="vertical">

	<TextView
		android:id="@+id/textView"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_gravity="center"
		android:textColor="@color/black" />
</LinearLayout>

// MianActivity.java code :

public class MainActivity extends Activity
{
    // Array of strings...
    ListView simpleList;
    String countryList[] = {"India", "China", "australia", "Portugle", "America", "NewZealand"};

    @Override   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
        setContentView(R.layout.activity_main);
        //the code 
        simpleList = (ListView)findViewById(R.id.simpleListView);
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.custom_item, R.id.textView, countryList);
        simpleList.setAdapter(arrayAdapter);
    }
}
Posted by: Guest on October-24-2021
0

how to use listview in android studio

ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.ListView,StringArray);
Posted by: Guest on June-20-2021

Code answers related to "android studio listview"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language