我是新來的android有一個標籤佈局與片段,我有一個編輯文本字段,這是我的父活動中聲明,我想檢查天氣編輯文本字段爲空或不是從片段我該怎麼做,這是我做了什麼,但它是示值誤差 這是我的主要活動編輯文本字段:如何從片段活動調用MainActivity變量
search_edit_text = (FloatingEditText)findViewById(R.id.edt_missile_number);
search_edit_text.setInputType(InputType.TYPE_CLASS_NUMBER);
search_edit_text.setGravity(Gravity.CENTER);
search_edit_text.setCursorVisible(false);
search_edit_text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
search_edit_text.setCursorVisible(true);
}
});
這是我的片段活動:
public class Manual_AC_Fuse_ckt extends Fragment {
static Manual manual_child; //MANUAL----->PARENT CLASS NAME
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Root_view = inflater.inflate(R.layout.manualmode_ac_fuse_ckt, null);
manual_child = new Manual();
(CheckBox)Root_view.findViewById(check_box_count_fuse_after_cnc[i]);
registerForContextMenu(table_fuse_afer_cnc);
return Root_view;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("MANUAL MODE : CONNECTION");
menu.add(1, v.getId(), 0, "TEST ");
menu.add(1, v.getId(), 0, "SELECT ALL ");
menu.add(1, v.getId(), 0, "DESELECT ALL ");
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="TEST ")
{
if(manual_child.search_edit_text.equals(""))
{
Toast.makeText(getActivity(),"Empty Message",Toast.LENGTH_LONG).show();
}
}
}
這是我的logcat:
01-02 07:27:25.830: E/AndroidRuntime(28243): FATAL EXCEPTION: main
01-02 07:27:25.830: E/AndroidRuntime(28243): java.lang.NullPointerException
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.developer.milanandroid.Manual_AC_Fuse_ckt.onContextItemSelected(Manual_AC_Fuse_ckt.java:120)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.support.v4.app.Fragment.performContextItemSelected(Fragment.java:1909)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.support.v4.app.FragmentManagerImpl.dispatchContextItemSelected(FragmentManager.java:2058)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:359)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:3644)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:167)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2788)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.widget.AbsListView$1.run(AbsListView.java:3473)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.os.Handler.handleCallback(Handler.java:730)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.os.Handler.dispatchMessage(Handler.java:92)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.os.Looper.loop(Looper.java:137)
01-02 07:27:25.830: E/AndroidRuntime(28243): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-02 07:27:25.830: E/AndroidRuntime(28243): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 07:27:25.830: E/AndroidRuntime(28243): at java.lang.reflect.Method.invoke(Method.java:525)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-02 07:27:25.830: E/AndroidRuntime(28243): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-02 07:27:25.830: E/AndroidRuntime(28243): at dalvik.system.NativeStart.main(Native Method)