Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 带有详细布局更新的片段_User Interface_Click_Fragment_Detail - Fatal编程技术网

User interface 带有详细布局更新的片段

User interface 带有详细布局更新的片段,user-interface,click,fragment,detail,User Interface,Click,Fragment,Detail,我已经用碎片编写了一个Android应用程序。一个ListView片段和一个detail片段。 我想做的是,如果有人在细节活动中单击,一个布局“View.go”应该是“View.Visible”。代码正常工作,但屏幕上没有任何更改。 您可以在ImageButton btn上的clik事件所在的片段代码中看到它的详细信息。 我错了什么 更新详细信息屏幕的最佳方式是什么?如果有人有一个小例子,或者可以给我写代码中我必须更改的地方,这会让我很高兴:-) 谢谢 汤姆 碎片活动: public class

我已经用碎片编写了一个Android应用程序。一个ListView片段和一个detail片段。 我想做的是,如果有人在细节活动中单击,一个布局“View.go”应该是“View.Visible”。代码正常工作,但屏幕上没有任何更改。 您可以在ImageButton btn上的clik事件所在的片段代码中看到它的详细信息。 我错了什么

更新详细信息屏幕的最佳方式是什么?如果有人有一个小例子,或者可以给我写代码中我必须更改的地方,这会让我很高兴:-) 谢谢 汤姆

碎片活动:

public class CacheFragment extends SherlockFragmentActivity {
 CacheListFragment f;

 @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.list_cachelist);

    f = new CacheListFragment();
    // Supply index input as an argument.
  Bundle args = new Bundle();
  f.setArguments(args);
}
这里是详细信息片段,您可以看到如果有人单击Imagebutton会发生什么:

public class CacheDetailsFragment extends SherlockFragment implements OnClickListener {
    private CacheDetailsLoading  cdLoad= new CacheDetailsLoading(); 
    private static GeocacheDetails _cacheDetails = new GeocacheDetails();
    private static GCRatingTyp _cacheVote = new GCRatingTyp();
    private CacheDetailsUsing cdUsing = new CacheDetailsUsing();
    private Activity _context;   
    private static CacheDetailsFragment f;
    private View view;
    /**
    * Create a new instance of DetailsFragment, initialized to
    * show the text at 'index'.
    */
    public static CacheDetailsFragment newInstance(int index ) {
        f = new CacheDetailsFragment();
        // Supply index input as an argument.
        Bundle args = new Bundle();
        args.putInt("index", index);
        f.setArguments(args);
        return f;
    }
    public int getShownIndex() {
        return getArguments().getInt("index", 0);
    }
    public void setCacheDetail(GeocacheDetails cacheDetails)
    {
    _cacheDetails = cacheDetails;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    if (container == null) {

        return null;
    }


    Bundle bundle=getArguments(); 
    _cacheVote= bundle.getParcelable("cacheVote");
    int index = bundle.getInt("index");
    _cacheDetails=StaticCacheListByGroup.getCacheList().get(index);

    _context =  getActivity();
    _context.setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);

            view = inflater.inflate(R.layout.list_cachedetails, container,false);
            ((RelativeLayout) view.findViewById(R.id.relativeLoggingInfo)).setVisibility(View.GONE);
            ((RelativeLayout) view.findViewById(R.id.relativeKategorienInfo)).setVisibility(View.GONE);


        ImageButton btn = (ImageButton) view.findViewById(R.id.description_expand);
        btn.setOnClickListener(new OnClickListener() {
        public void onClick(View v)
        {
            if(((RelativeLayout) getActivity().findViewById(R.id.relativeDescriptionInfo)).getVisibility() ==  View.GONE)
            {
                    ((ImageButton) getActivity().findViewById(R.id.description_expand)).setBackgroundResource(R.drawable.navigation_collapse_dark);
                    ((RelativeLayout) getActivity().findViewById(R.id.relativeDescriptionInfo)).setVisibility(View.VISIBLE);

                }
                else
                {
                    ((ImageButton) getActivity().findViewById(R.id.description_expand)).setBackgroundResource(R.drawable.navigation_expand_dark);   
                    ((RelativeLayout) getActivity().findViewById(R.id.relativeDescriptionInfo)).setVisibility(View.GONE);
                }                 
        });       
        return view;
    }

}
现在,列表片段:

public class CacheListFragment extends SherlockListFragment {
boolean isDualPane;
int mCurCheckPosition = 0;
private CacheListArrayAdapter _adapter;
private SharedPrefs _sp= new SharedPrefs();
private double latitude=0;
private double longitude=0;


@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);



    latitude =Double.parseDouble(_sp.getSharedPrefs(getActivity(), LibraryDefaults.PROGRAMMNAME, "Latitude", "0"));
    longitude =Double.parseDouble(_sp.getSharedPrefs(getActivity(), LibraryDefaults.PROGRAMMNAME, "Longitude", "0"));


    // Check to see if we have a frame in which to embed the details
    // fragment directly in the containing UI.
    View detailsFrame = getActivity().findViewById(R.id.details);
    isDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;

    if(!isDualPane)
    {
        Bundle bundle = getActivity().getIntent().getExtras();
        if(bundle != null && bundle.containsKey("Titel"))
            ((TextView) getActivity().findViewById(R.id.listtitle)).setText(bundle.getString("Titel"));
        else
            ((TextView) getActivity().findViewById(R.id.listtitle)).setText(this.getResources().getString(R.string.caches_listtitle));

    }

    if (StaticCacheListByGroup.getCacheList() != null)
    {
         GeocachingCompass gc = new GeocachingCompass(getActivity());
        _adapter = new CacheListArrayAdapter(getActivity(), StaticCacheListByGroup.getCacheList(), longitude,latitude);
        _adapter.setActualCoordinates(new LatLng(latitude,longitude));
        _adapter.setActualHeading(gc.getBearing(latitude,longitude));
        if (_adapter != null) 
            setListAdapter(_adapter);

        if (savedInstanceState != null) {
            // Restore last state for checked position.
            mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
        }
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        getListView().setSoundEffectsEnabled(true);
        getListView().setSmoothScrollbarEnabled(true);
        getListView().setDrawSelectorOnTop(false);
        getListView().setCacheColorHint(R.color.transparentBlack);
        getListView().setDivider(getResources().getDrawable( R.color.divider));
        getListView().setDividerHeight(5);



        if (isDualPane) {
            // In dual-pane mode, the list view highlights the selected item.
            getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

            showDetails(mCurCheckPosition);
        }
    }

  }

@Override
public void onResume() {

    super.onResume();
     GeocachingCompass gc = new GeocachingCompass(getActivity());
    _adapter = new CacheListArrayAdapter(getActivity(), StaticCacheListByGroup.getCacheList(), longitude,latitude);
    _adapter.setActualCoordinates(new LatLng(latitude,longitude));
    _adapter.setActualHeading(gc.getBearing(latitude,longitude));
    if (_adapter != null) 
        setListAdapter(_adapter);

}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt("curChoice", mCurCheckPosition);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    showDetails(position);
}

/**
 * Helper function to show the details of a selected item, either by
 * displaying a fragment in-place in the current UI, or starting a
 * whole new activity in which it is displayed.
 */
void showDetails(int index) {
    mCurCheckPosition = index;

    ReadGCVote getVote = new ReadGCVote();
    GeocacheDetails cacheDetails = new GeocacheDetails();
    cacheDetails=StaticCacheListByGroup.getCacheList().get(index);


    if (isDualPane) {
        // We can display everything in-place with fragments, so update
        // the list to highlight the selected item and show the data.
        getListView().setItemChecked(index, true);

        // Check what fragment is currently shown, replace if needed.
        CacheDetailsFragment details = (CacheDetailsFragment)
                getActivity().getSupportFragmentManager().findFragmentById(R.id.details);
        if (details == null || details.getShownIndex() != index) {
            // Make new fragment to show this selection.
            details = CacheDetailsFragment.newInstance(index);

            // Execute a transaction, replacing any existing fragment
            // with this one inside the frame.
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.details, details);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.commit();
        }

    } else {

        // Otherwise we need to launch a new activity to display
        Intent intent = new Intent();
        intent.setClass(getActivity(), CacheDetailsActivity.class);
        intent.putExtra("index", index);
        intent.putExtra("cacheDetails",cacheDetails);
        intent.putExtra("cacheVote",getVote.getGCVoteByCacheGuid( StaticGCVoteList.getCacheList(), cacheDetails.GetGUID()));
        startActivity(intent);
    }
}

}
我发现了错误:-)

在详细信息片段的代码段中

    public void onClick(View v)
    {
        if(((RelativeLayout)  getActivity().findViewById(R.id.relativeDescriptionInfo)).getVisibility() ==  View.GONE)
    }
…您不应该使用“getActivity()”使用“view=inflater.inflate(R.layout.list_cachedetails,container,false)”中的“view”

那就行了