Answers for "listview android studio"

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

android java list view

ListView friendsListView = findViewById(R.id.friendListView);
final ArrayList<String> myFriends = new ArrayList<String>(asList("Mark","Jane","Sussy","Jan"));
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, myFriends);
friendsListView.setAdapter(arrayAdapter); // Set an adapter
friendsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
       Toast.makeText(getApplicationContext(), "Hello " + myFriends.get(i), Toast.LENGTH_LONG).show();
Posted by: Guest on January-05-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 "listview android studio"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language