• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Launch new activity from within a clickListener

Sugarat

Lurker
Hi,

Hope someone can assist. I'm trying to launch a new activity from my preferences fragment, but it seems that the new activity is not receiving a View.

SettingsFragment.java
Code:
package com.example.myfirstapp;

import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.Preference;
import android.content.Intent;
import com.coderplus.filepicker.FilePickerActivity;

public class SettingsFragment extends PreferenceFragment
{
	
	@Override
    public void onCreate(Bundle savedInstanceState)
	{
        super.onCreate(savedInstanceState);
 
        // Add in the preferences panel
        addPreferencesFromResource(R.xml.preferences);
        
    	Preference buttonFilePicker;
        
        // Now I want to set the behaviour of the button
        buttonFilePicker = (Preference)findPreference("buttonFilePicker");
                
        // Set the click activity for the button
        buttonFilePicker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference arg0) {
            	
            	// At this point we want to invoke the filePicker! 
            	System.out.println("BUTTON CLICKED!");
            	            	
            	//Some random integer used to identify the intent so that the data returned back can be identified
            	//static int REQUEST_PICK_FILE = 777;

            	Intent intent = new Intent(SettingsFragment.this.getActivity(), FilePickerActivity.class);
            	startActivityForResult(intent, 777);
            	
                return true;
            }
        });
	}
}

It seems that the FilePickerActivity is not able to see the View correctly. The error given when the application crashes is:
Code:
java.lang.NoClassDefFoundError: com.coderplus.filepicker.R$layout

How do I launch the FilePicker activity from this click listener....?

Many thanks
 
Back
Top Bottom