Skip to content

Most visited

Recently visited

navigation
BorderlessButtons / src / com.example.android.borderlessbuttons /

MainActivity.java

1
/*
2
 * Copyright 2013 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.borderlessbuttons;
18
 
19
import android.app.ListActivity;
20
import android.content.ActivityNotFoundException;
21
import android.content.Intent;
22
import android.net.Uri;
23
import android.os.Bundle;
24
import android.view.Menu;
25
import android.view.MenuItem;
26
import android.view.View;
27
import android.view.ViewGroup;
28
import android.widget.BaseAdapter;
29
import android.widget.Toast;
30
 
31
/**
32
 * This activity demonstrates the <b>borderless button</b> styling from the Holo visual language.
33
 * The most interesting bits in this sample are in the layout files (res/layout/).
34
 * <p>
35
 * See <a href="http://developer.android.com/design/building-blocks/buttons.html#borderless">
36
 * borderless buttons</a> at the Android Design guide for a discussion of this visual style.
37
 */
38
public class MainActivity extends ListActivity {
39
    private static final Uri DOCS_URI = Uri.parse(
40
            "http://developer.android.com/design/building-blocks/buttons.html#borderless");
41
 
42
    protected void onCreate(Bundle savedInstanceState) {
43
        super.onCreate(savedInstanceState);
44
        setContentView(R.layout.sample_main);
45
 
46
        setListAdapter(mListAdapter);
47
 
48
        findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
49
            @Override
50
            public void onClick(View view) {
51
                finish();
52
            }
53
        });
54
 
55
        findViewById(R.id.ok_button).setOnClickListener(new View.OnClickListener() {
56
            @Override
57
            public void onClick(View view) {
58
                finish();
59
            }
60
        });
61
    }
62
 
63
    private BaseAdapter mListAdapter = new BaseAdapter() {
64
        @Override
65
        public int getCount() {
66
            return 10;
67
        }
68
 
69
        @Override
70
        public Object getItem(int position) {
71
            return null;
72
        }
73
 
74
        @Override
75
        public long getItemId(int position) {
76
            return position + 1;
77
        }
78
 
79
        @Override
80
        public View getView(int position, View convertView, ViewGroup container) {
81
            if (convertView == null) {
82
                convertView = getLayoutInflater().inflate(R.layout.list_item, container, false);
83
            }
84
 
85
            // Because the list item contains multiple touch targets, you should not override
86
            // onListItemClick. Instead, set a click listener for each target individually.
87
 
88
            convertView.findViewById(R.id.primary_target).setOnClickListener(
89
                    new View.OnClickListener() {
90
                        @Override
91
                        public void onClick(View view) {
92
                            Toast.makeText(MainActivity.this,
93
                                    R.string.touched_primary_message,
94
                                    Toast.LENGTH_SHORT).show();
95
                        }
96
                    });
97
 
98
            convertView.findViewById(R.id.secondary_action).setOnClickListener(
99
                    new View.OnClickListener() {
100
                        @Override
101
                        public void onClick(View view) {
102
                            Toast.makeText(MainActivity.this,
103
                                    R.string.touched_secondary_message,
104
                                    Toast.LENGTH_SHORT).show();
105
                        }
106
                    });
107
            return convertView;
108
        }
109
    };
110
 
111
    @Override
112
    public boolean onCreateOptionsMenu(Menu menu) {
113
        super.onCreateOptionsMenu(menu);
114
        getMenuInflater().inflate(R.menu.main, menu);
115
        return true;
116
    }
117
 
118
    @Override
119
    public boolean onOptionsItemSelected(MenuItem item) {
120
        switch (item.getItemId()) {
121
            case R.id.docs_link:
122
                try {
123
                    startActivity(new Intent(Intent.ACTION_VIEW, DOCS_URI));
124
                } catch (ActivityNotFoundException ignored) {
125
                }
126
                return true;
127
        }
128
        return super.onOptionsItemSelected(item);
129
    }
130
}
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.