ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [ANDROID] AQUERY를 이용한 초간단 리스트뷰 생성
    0x05 Programming/Android Programing 2014. 1. 9. 10:23

    package com.example.j0ker0109a;


    import java.util.ArrayList;


    import com.androidquery.AQuery;


    import android.os.Bundle;

    import android.app.Activity;

    import android.util.Log;

    import android.view.Menu;

    import android.view.View;

    import android.widget.ArrayAdapter;

    import android.widget.AdapterView;


    public class MainActivity extends Activity {


    private ArrayList<String> arrayList;

    private ArrayAdapter<String> arrayAdapter;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);


    AQuery aq = new AQuery(this);

    arrayList = new ArrayList<String>();


    for(int i=0; i < 10; i++) {

    arrayList.add(i+"번째 리스트뷰입니다");

    }


    arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList);


    // aq.id(R.id.listView).adapter();

    aq.id(R.id.listView).adapter(arrayAdapter);

    aq.id(R.id.listView).itemClicked(mItemOnClickListener);


    }


    private AdapterView.OnItemClickListener mItemOnClickListener = new AdapterView.OnItemClickListener() {


    @Override

    public void onItemClick(AdapterView<?> parent, View view, int position,

    long id) {

    // TODO Auto-generated method stub

    String myString = position+"번째 리스트입니다";

    Log.i("MainActivity onItemClick",myString);


    }


    };


    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.

    getMenuInflater().inflate(R.menu.main, menu);

    return true;

    }


    }


Designed by Tistory.