Eclipse will not show 2.3 emulator for android compatibility package code

Posted by Mark Lasby on Stack Overflow See other posts from Stack Overflow or by Mark Lasby
Published on 2012-09-17T03:36:55Z Indexed on 2012/09/17 3:37 UTC
Read the original article Hit count: 442

I am trying to learn fragments to modernize an app I originally wrote for android 1.5 that uses Date Picker Dialog. I am using the android-support-v4 library. When I run the code in Eclipse Juno 20120614-1722 it only shows android 4.0 emulators and there is a red X beside my Samsung phone running 2.3.5. When I push the package to phone, the code runs.

Here is the code

FragTestActivity.java

package xyz.marklasby.fragtest;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;

public class FragTestActivity extends FragmentActivity {

private Button date;
private Calendar now;
private SimpleDateFormat sdf = new SimpleDateFormat(" EEE MMM dd/yyyy");

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    date = (Button) findViewById(R.id.setdate);
    now = Calendar.getInstance();
    date.setText(sdf.format(now.getTime()));

    date.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    editDate(v);
    }
});
}

public void editDate(View v) {
DialogFragment newFragment = DatePickerFragment.newInstance(new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    now.set(year, monthOfYear, dayOfMonth);
    date.setText(sdf.format(now.getTime()));
    }
});
newFragment.show(getSupportFragmentManager(), "datePicker");
}
}

DatePickerFragment.java

package xyz.marklasby.fragtest;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

public class DatePickerFragment extends DialogFragment {

static DatePickerDialog.OnDateSetListener mListener;

public static DatePickerFragment newInstance(DatePickerDialog.OnDateSetListener listener) {
mListener = listener;
return new DatePickerFragment();
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), mListener, year, month, day);

}
}

Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.marklasby.fragtest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".FragTestActivity"
        android:label="@string/title_activity_frag_test" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about android-emulator

Related posts about android-compat-lib