1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.apis.view; 18 19 import com.example.android.apis.R; 20 21 import android.app.Activity; 22 import android.os.Bundle; 23 import android.view.View; 24 import android.widget.AdapterView; 25 import android.widget.ArrayAdapter; 26 import android.widget.ListAdapter; 27 import android.widget.ListView; 28 import android.widget.Toast; 29 import android.widget.AdapterView.OnItemClickListener; 30 31 32 /** 33 * Demonstrates splitting touch events across multiple views within a view group. 34 */ 35 public class SplitTouchView extends Activity { 36 @Override 37 protected void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 40 setContentView(R.layout.split_touch_view); 41 ListView list1 = (ListView) findViewById(R.id.list1); 42 ListView list2 = (ListView) findViewById(R.id.list2); 43 ListAdapter adapter = new ArrayAdapter<String>(this, 44 android.R.layout.simple_list_item_1, Cheeses.sCheeseStrings); 45 list1.setAdapter(adapter); 46 list2.setAdapter(adapter); 47 48 list1.setOnItemClickListener(itemClickListener); 49 list2.setOnItemClickListener(itemClickListener); 50 } 51 52 private int responseIndex = 0; 53 54 private final OnItemClickListener itemClickListener = new OnItemClickListener() { 55 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 56 String[] responses = getResources().getStringArray(R.array.cheese_responses); 57 String response = responses[responseIndex++ % responses.length]; 58 59 String message = getResources().getString(R.string.split_touch_view_cheese_toast, 60 Cheeses.sCheeseStrings[position], response); 61 62 Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT); 63 toast.show(); 64 } 65 }; 66 } 67