Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TEACHING-MATERIALS/Week_05_AdapterViews_and_Fragments/MyFragments/app/src/main/java/com/example/jianhuayang/myfragments/DetailsFragment.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (39 sloc)
1.54 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jianhuayang.myfragments; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import com.example.jianhuayang.myfragments.data.Candidates; | |
/** | |
* A simple {@link Fragment} subclass. | |
*/ | |
public class DetailsFragment extends Fragment { | |
public static final String POSITION = "position"; | |
public DetailsFragment() { | |
// Required empty public constructor | |
} | |
@Override | |
public void onStart() { | |
super.onStart(); | |
Bundle args = getArguments(); | |
if (args != null) { | |
int position = args.getInt(POSITION); | |
TextView description = (TextView) getActivity().findViewById(R.id.description); | |
description.setText(Candidates.candidateDetails[position]); | |
ImageView imageView = (ImageView) getActivity().findViewById(R.id.imageView); | |
imageView.setImageResource(Candidates.candidatePhotos[position]); | |
} else { | |
TextView description = (TextView) getActivity().findViewById(R.id.description); | |
description.setText("Click on the names on the left to see details"); | |
} | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// Inflate the layout for this fragment | |
return inflater.inflate(R.layout.fragment_details, container, false); | |
} | |
} |