• 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
Mar 11, 2014
1
0
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
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones