Category Archives: Android

Android Studio was unable to find a valid Jvm on MAC #Solved

If you have installed Android Studio on your MAC, you may run into an error that says “Android Studio was unable to find a valid Jvm” when you try to open this up. After a little work I was able to get it fixed and here is how I did it.

The problem:
/Applications/Android Studio.app/Contents/Info.plist has a setting in there that is looking for JDK 1.6*. Any good computer user will update their java as they need to so chances are that you will have 1.7 or even 1.8.

The solution:
We just have to tell Info.plist to look for your version instead of 1.6

The steps:

    1. Go here and check which java version that you have – https://www.java.com/en/download/installed.jsp.
      1. Mine was 1.8
    2. Edit /Applications/Android Studio.app/Contents/Info.plist
      1. May live somewhere else on your machine
    3. Change
      1. <key>JVMVersion</key>
        <string>1.6*</string>
    4. to
      1. <key>JVMVersion</key>
        <string>1.(7 or 8)*</string>
    5. Save and exit

That fixed me right up and I was able to start working in the tool.

Hope it helps.

Advertisements
Tagged ,

Android setOnKeyListener in Dialog

It took me a few tries to get the onKeyListener to work on a dialog EditText. The key is to use View.OnKeyListener() instead of just OnKeyListener().

Here is the code:

		final Dialog newReminderDialog = new Dialog(getActivity());
		newReminderDialog.setContentView(R.layout.dialog_new_reminder);
		newReminderDialog.setTitle("Set Time");
		newReminderDialog.show();
		EditText addToTimeEditText = (EditText) newReminderDialog.findViewById(R.id.addToTimeEntry);
		addToTimeEditText.setOnKeyListener(new View.OnKeyListener(){
			@Override
			public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
				// TODO Auto-generated method stub
				Toast.makeText(getActivity(), "t", Toast.LENGTH_SHORT).show();
				return true;
			}
			
		});
Tagged , , ,

Android use ArrayList to handle Fragments

As you dive into the current world of Android development, you will be dealing more and more with Fragments and less with new Activities. Weather you choose a dropdown or tabbed navigation it is a good idea to create some sort of array of your Fragments that can map to the positions returned by the dropdown or tabs.

Here is the code from my MainActivity:

@Override
		public Fragment getItem(int position) {
			// getItem is called to instantiate the fragment for the given page.
			ArrayList <Fragment> fragments = new ArrayList <Fragment>();
			fragments.add(new ReminderFragment());
			fragments.add(new PatientFragment());
			fragments.add(new StopWatchFragment());
			Fragment fragment = fragments.get(position);
			Bundle args = new Bundle();
			fragment.setArguments(args);
			return fragment;
		}

When a tab is selected this function is run and the position arg sent can be used as an array index for getting the correct fragment. All you have to do is create and ArrayList and add the fragments in the same order as their tabs. This keeps the fuction smaller and more scalable.

Tagged , , ,