So I have this spinner where I want to find what the selected item is. I got something in place to remember what the item which is selected. Now there is a button to click within the same layout where the spinner is, this will bring up a dialog box which tells which item you have selected. But I am getting error , on my log cat it says "java.lang.NullPointerException"
This is my XML file for the Dialog Box;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffc0c0c0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Saving's Account"
android:id="@+id/spinnerSelectedText"
android:textColor="#ff000000"
android:drawableLeft="@drawable/transferaccount_icon"
android:drawablePadding="10dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:textSize="16sp" />
</RelativeLayout>
This is my java file which is for the dialog ;
public class examplefile extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inf = getActivity().getLayoutInflater();
View theDIalog = inf.inflate(R.layout.makea_transfer_confirm, null);
builder.setView(theDIalog);
builder.setCancelable(true);
return dialog;
}
}
Now this is the screen that you get when you start off - well after the main activity class but I don't want to share the code from main activity since i believe it's not necessary;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View v = inflater.inflate(R.layout.makea_transfer, container, false);
spinner = (Spinner)v.findViewById(R.id.spinnermakeatransfer);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.accounts,R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_items);
spinner.setAdapter(adapter);
spinner.setPrompt("Select an item");
Spinner spinner1 = (Spinner)v.findViewById(R.id.spinnermakeatransfer);
String spinnerSelectedItem = spinner1.getSelectedItem().toString();
TextView spinnerText = (TextView) v.findViewById(R.id.spinnerSelectedText);
spinnerText.setText(spinnerSelectedItem);
return v;
}
Now this is the makea_transfer XML ;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinnermakeatransfer"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingTop="5dp"
android:spinnerMode="dialog"
android:layout_marginTop="5dp"
android:touchscreenBlocksFocus="false" />
</RelativeLayout>
Please can someone help me fix this issue, please comment if you don't understand or need more details from me.
This is the Log Cat Click Here