Search in sources :

Example 51 with AdapterView

use of android.widget.AdapterView in project AndroidSDK-RecipeBook by gabu.

the class Recipe046 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    // リストアイテムを追加
    for (int i = 0; i < 20; i++) {
        mAdapter.add("item_" + i);
    }
    // ListViewを取得
    ListView listView = (ListView) findViewById(R.id.ListView01);
    // ListViewにフッターを追加
    // 必ずsetAdapterの前に呼び出すこと
    listView.addFooterView(getLayoutInflater().inflate(R.layout.footer, null), null, true);
    // ListViewにAdapterを追加
    listView.setAdapter(mAdapter);
    // リスナーをセット
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // クリックされたViewがフッターか判定
            if (view.getId() == R.id.Footer) {
                // 表示する数字を計算
                int count = mAdapter.getCount();
                int max = count + 5;
                for (; count < max; count++) {
                    // リストアイテムを追加
                    mAdapter.add("item_" + count);
                }
            }
        }
    });
}
Also used : ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 52 with AdapterView

use of android.widget.AdapterView in project coursera-android by aporter.

the class AutoCompleteActivity method onCreate.

/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Get a reference to the AutoCompleteTextView
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
    // Create an ArrayAdapter containing country names
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
    // Set the adapter for the AutoCompleteTextView
    textView.setAdapter(adapter);
    textView.setOnItemClickListener(new OnItemClickListener() {

        // Display a Toast Message when the user clicks on an item in the AutoCompleteTextView
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Toast.makeText(getApplicationContext(), "The winner is:" + arg0.getAdapter().getItem(arg2), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 53 with AdapterView

use of android.widget.AdapterView in project coursera-android by aporter.

the class GalleryActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Gallery g = (Gallery) findViewById(R.id.gallery);
    // Create a new ImageAdapter and set in as the Adapter for the Gallery
    g.setAdapter(new ImageAdapter(this));
    // Set an setOnItemClickListener on the Gallery
    g.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // Display a Toast message indicate the selected item
            Toast.makeText(GalleryActivity.this, "" + position, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Gallery(android.widget.Gallery) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 54 with AdapterView

use of android.widget.AdapterView in project coursera-android by aporter.

the class GridLayoutActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    GridView gridview = (GridView) findViewById(R.id.gridview);
    // Create a new ImageAdapter and set it as the Adapter for this GridView
    gridview.setAdapter(new ImageAdapter(this, mThumbIdsFlowers));
    // Set an setOnItemClickListener on the GridView
    gridview.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            //Create an Intent to start the ImageViewActivity
            Intent intent = new Intent(GridLayoutActivity.this, ImageViewActivity.class);
            // Add the ID of the thumbnail to display as an Intent Extra
            intent.putExtra(EXTRA_RES_ID, (int) id);
            // Start the ImageViewActivity
            startActivity(intent);
        }
    });
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Intent(android.content.Intent) GridView(android.widget.GridView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 55 with AdapterView

use of android.widget.AdapterView in project coursera-android by aporter.

the class ListViewActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Create a new Adapter containing a list of colors
    // Set the adapter on this ListActivity's built-in ListView
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, getResources().getStringArray(R.array.colors)));
    ListView lv = getListView();
    // Enable filtering when the user types in the virtual keyboard
    lv.setTextFilterEnabled(true);
    // Set an setOnItemClickListener on the ListView
    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Display a Toast message indicting the selected item
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : ListView(android.widget.ListView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Aggregations

AdapterView (android.widget.AdapterView)677 View (android.view.View)653 ListView (android.widget.ListView)412 TextView (android.widget.TextView)342 Intent (android.content.Intent)177 ImageView (android.widget.ImageView)174 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)142 ArrayAdapter (android.widget.ArrayAdapter)75 ArrayList (java.util.ArrayList)71 ViewGroup (android.view.ViewGroup)63 AbsListView (android.widget.AbsListView)59 GridView (android.widget.GridView)58 Bundle (android.os.Bundle)53 Spinner (android.widget.Spinner)50 LinearLayout (android.widget.LinearLayout)49 OnClickListener (android.view.View.OnClickListener)46 RecyclerView (android.support.v7.widget.RecyclerView)42 DialogInterface (android.content.DialogInterface)41 SuppressLint (android.annotation.SuppressLint)38 LayoutInflater (android.view.LayoutInflater)34