안드로이드

 

 

 

 

class ListAdataterActivity

 

package com.example.choi.mystudy8;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class ListAdataterActivity extends AppCompatActivity {
    ArrayList<String> arrayList=null;
    ArrayAdapter<String> adapter=null;
    ListView listView=null;

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

        arrayList=new ArrayList<>();
        arrayList.add("월");
        arrayList.add("화");
        arrayList.add("수");
        arrayList.add("목");
        arrayList.add("금");
        arrayList.add("토");
        arrayList.add("일");

        adapter=new ArrayAdapter<String>(ListAdataterActivity.this, android.R.layout.simple_list_item_1, arrayList);

        listView=(ListView)findViewById(R.id.lv_01);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Toast.makeText(ListAdataterActivity.this, arrayList.get(position).toString(),
                        Toast.LENGTH_SHORT).show();

            }
        });

    }






}









 

 

activity_list_adatater.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_list_adatater"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.choi.mystudy8.ListAdataterActivity">

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




    </ListView>
    
    
</RelativeLayout>

 

 


 

 

 

 

 

 

 

class PatitionAtivity
package com.example.choi.mystudy8;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class PatitionAtivity extends AppCompatActivity {

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

        ArrayAdapter<CharSequence> adapter =ArrayAdapter.createFromResource(this,
                R.array.weather, android.R.layout.simple_list_item_checked);
        final ListView listView =(ListView)findViewById(R.id.list1);
        listView.setAdapter(adapter);


        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setDivider(new ColorDrawable(Color.GREEN));
        listView.setDividerHeight(3);


        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Toast.makeText(PatitionAtivity.this, String.valueOf(position), Toast.LENGTH_SHORT).show();


            }
        });
    }




}

 

 

activity_patition_ativity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_patition_ativity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.choi.mystudy8.PatitionAtivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/list1" />
</RelativeLayout>

 

 

 

android

 

about author

PHRASE

Level 60  머나먼나라

소경 기름값 내기 , 이해 관계도 없이 남과 같이 부담한다는 말.

댓글 ( 4)

댓글 남기기

작성