library management
download google chrome
its very usefull... thannk u
TextView
. You need to delete this piece of code:
RelativeLayout
element:
findviewById(int id)
method.
Open MainActivity.java and add a private member to the MainActivity class:
linkthis button with the button from the xml file. It's done using button id:Setting the current class to be click listener for this button forces as to implement the interface
select.setOnClickListener(this);OnClickListener
. At this moment, activity class looks in the following way:
package com.example.testlist; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity implements OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); select.setOnClickListener(this); } @Override } }We are ready now to start the most interesting part of this project: the implementation of preferences option. For this purpose we will use the
PreferenceScreen
withRingtonePreference
We need to add a new activity to the project. So, we need to add a record to the manifest file first:I called my activity
<activity android:name=".SoundSelect" android:theme="@android:style/Theme.Black.NoTitleBar"/>SoundSelect
. Now, we can add the activity to the project and the layout file, called sound_select.xml to the project. The sound select is corresponding for the selection layout and it looks in this way:The corresponding activity file, that loads the option screen has the following structure:
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="center" > <PreferenceCategory android:summary="Alarm sound" android:title="Select Sound" > <RingtonePreference android:id="@+id/ringtone" android:showDefault="true" android:layout_width ="wrap_content" android:layout_height="wrap_content" android:key="Alarm" android:summary="Alarm" android:ringtoneType="notification|alarm" /> </PreferenceCategory> </PreferenceScreen>You can see, that just one line is added to the standard declaration of an activity:
package com.example.testlist; import android.os.Bundle; import android.preference.PreferenceActivity; public class SoundSelect extends PreferenceActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.sound_select); } }The work is almost done! Now, we come back to the main activity and specify the on click listener for the sound button:
addPreferencesFromResource(R.layout.sound_select);That's all. Now the result is:
Intent intent = new Intent(MainActivity.this, SoundSelect.class); startActivity(intent);The sound names are shown according to the system locale. That's why you can see Russian letters in the screen.