2. Spinner OR Drop Down List
Spinner allows you to select an item from a
drop down menu
3. For example. When you are using Gmail application you would get drop
down menu as shown below, you need to select an item from a drop down
menu.
4. Two ways for creation of
Spinner
1. Create a array in xml and attach to
spinner
2. Declare Spinner in XML , Create Adapter
in java and assign value to spinner
through adapter.
5. Drop Down menu using
Spinner
<Spinner
android:id="@+id/spiner1"
android:layout_width="match_parent"
android:layout_height="80dp" />
6. Adapter
An Adapter object acts as a bridge between
an AdapterView and the underlying data for
that view. The Adapter provides access to
the data items. The Adapter is also
responsible for making a View for each item
in the data set.
7. Spinner in java
public class MainActivity extends AppCompatActivity {
@Override
Spinner sp;
String[] cities = {"Sargodha", "Lahore", "Islamabad"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = findViewById(R.id.spiner1);
ArrayAdapter adp = new ArrayAdapter(this,
R.layout.support_simple_spinner_dropdown_item, cities);
adp.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
sp.setAdapter(adp);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
Toast.makeText(MainActivity.this, cities[position]),
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
11. public class MainActivity extends AppCompatActivity {
@Override
Spinner sp;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = findViewById(R.id.spiner1);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
Toast.makeText(MainActivity.this, sp.getSelected().toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
12. Intent in Android
Android Intent is the message that is
passed between components such as
activities, content providers, broadcast
receivers, services etc. It is generally used
with startActivity() method to invoke activity,
broadcast receivers etc. The dictionary
meaning of intent is intention or purpose.
13. Types of Android Intents
1) Explicit Intent
Communication between activates of same
application.
2) Implicit Intent
Transfer data between applications.
14. Explicit Intent
Android Splash Screen is the first screen
visible to the user when the application's
launched. ... Splash screens are used to
display some animations (typically of the
application logo) and illustrations while some
data for the next screens are fetched.