Using listview in android

前端 未结 7 1950
你的背包
你的背包 2020-12-21 18:30

I am making an android application that needs to use a ListView. I want to add a menubutton that says \"Add to list\" and once the user presses that menubutton,

7条回答
  •  有刺的猬
    2020-12-21 18:50

    MainActivity.java

          com.jtech.listviewapp;
          import androidx.appcompat.app.AppCompatActivity;
    
          import android.os.Bundle;
          import android.widget.ArrayAdapter;
          import android.widget.ListView;
    
          public class MainActivity extends AppCompatActivity {
            ListView listView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            listView = (ListView) findViewById(R.id.lv);
            String days[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
            ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,days);
            listView.setAdapter(arrayAdapter);
        }
    }
    

提交回复
热议问题