What?
A reference to what size an image background should be set to for various screen sizes.

Why?
A background image I was using was unedited at 1600x2133 (364kb) and was not displaying on smaller devices. Configuring drawables for each layout seemed to be the only solution.

res/drawable-ldpi      240x320
res/drawable-mdpi      320x480
res/drawable-hdpi      480x800
res/drawable-xhdpi     640x960
res/drawable-xxhdpi    960x1440
res/drawable-xxxhdpi   // for launcher only 640dpi
res/drawable-tvdpi     1.33*mdpi // not needed as mdpi or hdpi is used


What?
A quick article on how to replace the return key on a soft keyboard (software based) on a touch-device.

Why?
I have an editText where a user can enter any text value but if they typed a return character, the app would crash because it didn't understand the data. I tried replacing the new lines but just stopping the return key or trying to catch it is an obsolete method.

How?

What?
If you're installing an app and it creates two icons:

Why?
I don't think I'll forget this one but I was stumped for a bit until I found it on the a forum: Stack Overflow: Android App Development.

How?
Basically don't have the following declared more than once in the AndroidManifest.xml
<intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>


What?
A quick article on how to display a OK/Cancel popup which I use as a message to the user for debug purposes.

Why?
It's similar to javascript's message box or confirm box, only Android let's you redesign the dialog. For my purposes I have used an XML as the layout.

How?
This displays a standard Ok/cancel message popup which you attach to some event
import android.app.AlertDialog;
import android.content.DialogInterface;

new AlertDialog.Builder(this)
        .setTitle("Some Title")
        .setMessage("some message")
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                        // Some stuff to do when ok got clicked
                }
        })
        .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                        // Some stuff to do when cancel got clicked
                }
        })
        .show();


Additional: Pre-populating default value and returning input
Lots of confusing answers out there on the web but here's an all-in-one where I
  • Open an AlertDialog designed with a custom XML layout
  • Set the hint text of a specific user input field (EditText)
  • Store the input in a TextView (invisible or visible) held in the calling XML
/* 201411041253 */
private String hangar_aircraft_name;

public void editHangarAircraftName(View view) {

        // get current value for hint
        TextView currentName = (TextView) findViewById(R.id.hangar_aircraft_001_header);
        hangar_aircraft_name = currentName.getText().toString();

        // get the AlertDialog XML layout file
        final View v = getLayoutInflater().inflate(R.layout.my_custom_dialog, null);

        // set the hint of the EditText in the AlertDialog
        EditText inputText = (EditText) v.findViewById(R.id.hangar_item_menu_name_field);
        inputText.setHint(hangar_aircraft_name);

        // Start building the AlertDialog
        AlertDialog.Builder b = new AlertDialog.Builder(this);

        // set the view of the AlertDialog along with changes (eg. changed "hint")
        b.setView(v);

        // set OK button action
        b.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {

                        // Get the f !!!
                        Dialog f = (Dialog) dialog;

                        // this is the EditText that has the value I want
                        EditText inputTemp = (EditText) f.findViewById(R.id.my_input_field);  

                        // this is the TextView to store the value in (not the AlertDialog but main xml)
                        TextView newName = (TextView) findViewById(R.id.hangar_aircraft_001_name);  

                        // setting header text to returned input
                        newName.setText(inputTemp.getText().toString());  
                }
        });

        // set Cancel button action
        b.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                }
        });

        // create and show the alertDialog
        b.create().show();
}
The key mistake I was doing was trying to recalculate which view the main activity item was in.

Related Articles

Joes Revolver Map

Joes Word Cloud

value   where   program   parameter   name   joomla   system   server   page   added   script   following   windows   date   first   would   license   version   time   files   select   display   mysql   table   user   website   search   site   data   google   content   using   zoho   used   file   copy   error   report   uploaded   need   code   work   note   could   solution   find   html   list   source   database   JoelLipman.Com

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate
© 2021 Joel Lipman .com. All Rights Reserved.