Android Programming Tutorials

(Romina) #1
Opening a JAR

return(super.onOptionsItemSelected(item));
}

You will also need to add some imports (Intent, Menu, MenuInflater,


MenuItem) to allow this to compile.


At this point, you can recompile and reinstall the application and see our


preference activity in action, even though the values are not being used yet:


Figure 33. The preference screen for Patchy

Step #4: Use Account Information from Preferences......................


Now, we can get rid of the extraneous widgets on our layout and use the


preferences for our account information. We can even arrange to update


our Twitter object when the user changes account information.


First, go into Patchy/res/layout/main.xml and get rid of the first two


TableRow elements, leaving you with:


<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
>
<TableRow>
<TextView android:text="Status:" />
<EditText android:id="@+id/status"
android:singleLine="false"
android:gravity="top"
android:lines="5"

170
Free download pdf