Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created July 25, 2022 08:30
Show Gist options
  • Save codeforfun-jp/9ed96f843cce53196432bb9cbc52d963 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/9ed96f843cce53196432bb9cbc52d963 to your computer and use it in GitHub Desktop.
【Java】ListView with one textview 4
package com.example.listviewsample;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// データを用意
String[] data = {
"とり", "しか", "ぞう", "きつね",
"かば", "ライオン", "パンダ", "ひつじ"
};
// ListViewにデータをセットする
ListView list = findViewById(R.id.list);
list.setAdapter(new ArrayAdapter<>(
this,
android.R.layout.simple_list_item_1,
data
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment