LoginSignup
19
22

More than 5 years have passed since last update.

[Android] ListView を使ってリスト表示をする方法

Posted at

Androidの勉強を初めて数日。
Javaの経験はあるのになんでAndroidってこんなわけわかんないの!?って毎日を送ってます。

とりあえず、レイアウトを決めてる xml と、その動作を決めてる Activity をいじります。

ゴール

Screen Shot 2014-06-12 at 17.10.56.png

layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

src/com.hoge.hoge.lvtest/MainActivity.java

package com.example.lvtest;





public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //ListViewのセット
        ListView listView = new ListView(this);
        setContentView(listView);

        //データの追加
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
        adapter.add("a");
        adapter.add("b");
        adapter.add("c");

        listView.setAdapter(adapter);
    }

  ・
  ・
  ・   

}

その他

まだタップした後の動作などは指定していないので、これからします。

19
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
22