Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. import java.util.Locale;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.support.v7.app.ActionBarActivity;
  5. import android.support.v4.app.Fragment;
  6. import android.support.v4.app.FragmentManager;
  7. import android.support.v4.app.FragmentPagerAdapter;
  8. import android.os.Bundle;
  9. import android.support.v4.view.ViewPager;
  10. import android.view.LayoutInflater;
  11. import android.view.Menu;
  12. import android.view.MenuItem;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.widget.ImageView;
  16. import android.widget.TextView;
  17.  
  18. import com.nostra13.universalimageloader.core.DisplayImageOptions;
  19. import com.nostra13.universalimageloader.core.ImageLoader;
  20. import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
  21. import com.nostra13.universalimageloader.core.assist.FailReason;
  22. import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
  23.  
  24.  
  25. public class ListItemClicked extends ActionBarActivity {
  26.  
  27. static Bundle extras;
  28.  
  29. SectionsPagerAdapter mSectionsPagerAdapter;
  30. static ImageLoader imageLoader;
  31. static DisplayImageOptions options;
  32.  
  33.  
  34.  
  35.  
  36. ViewPager mViewPager;
  37.  
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. setContentView(R.layout.list_item_clicked);
  42.  
  43.  
  44. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  45.  
  46. extras = getIntent().getExtras();
  47.  
  48. mViewPager = (ViewPager) findViewById(R.id.pager);
  49. mViewPager.setAdapter(mSectionsPagerAdapter);
  50.  
  51. //Setup the ImageLoader, we'll use this to display our images
  52. ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
  53. imageLoader = ImageLoader.getInstance();
  54. imageLoader.init(config);
  55.  
  56. //Setup options for ImageLoader so it will handle caching for us.
  57. options = new DisplayImageOptions.Builder()
  58. .cacheInMemory()
  59. .cacheOnDisc()
  60. .build();
  61.  
  62. }
  63.  
  64.  
  65. @Override
  66. public boolean onCreateOptionsMenu(Menu menu) {
  67. // Inflate the menu; this adds items to the action bar if it is present.
  68. getMenuInflater().inflate(R.menu.menu_main_activity2, menu);
  69. return true;
  70. }
  71.  
  72. @Override
  73. public boolean onOptionsItemSelected(MenuItem item) {
  74. int id = item.getItemId();
  75.  
  76. return id == R.id.action_settings || super.onOptionsItemSelected(item);
  77.  
  78. }
  79.  
  80.  
  81.  
  82. public class SectionsPagerAdapter extends FragmentPagerAdapter {
  83.  
  84. public SectionsPagerAdapter(FragmentManager fm) {
  85. super(fm);
  86. }
  87.  
  88. @Override
  89. public Fragment getItem(int position) {
  90. return PlaceholderFragment.newInstance(position + 1);
  91. }
  92.  
  93. @Override
  94. public int getCount() {
  95. return 2;
  96. }
  97.  
  98. @Override
  99. public CharSequence getPageTitle(int position) {
  100. Locale l = Locale.getDefault();
  101. switch (position) {
  102. case 0:
  103. return getString(R.string.title_section4).toUpperCase(l);
  104. case 1:
  105. return getString(R.string.title_section5).toUpperCase(l);
  106. }
  107. return null;
  108. }
  109. }
  110.  
  111.  
  112. public static class PlaceholderFragment extends Fragment {
  113.  
  114.  
  115. private static final String ARG_SECTION_NUMBER = "section_number";
  116.  
  117.  
  118. public static PlaceholderFragment newInstance(int sectionNumber) {
  119. PlaceholderFragment fragment = new PlaceholderFragment();
  120. Bundle args = new Bundle();
  121. args.putInt(ARG_SECTION_NUMBER, sectionNumber);
  122. fragment.setArguments(args);
  123. return fragment;
  124. }
  125.  
  126. public PlaceholderFragment() {
  127. }
  128.  
  129. @Override
  130. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  131. Bundle savedInstanceState)
  132. {
  133.  
  134. View rootView = inflater.inflate(R.layout.fragment_list_item_clicked, container, false);
  135.  
  136.  
  137. TextView pDate = (TextView) rootView.findViewById(R.id.textView);
  138. pDate.setText( extras.getString("pdate") );
  139.  
  140.  
  141. TextView ptitle = (TextView) rootView.findViewById(R.id.section_label);
  142. ptitle.setText(extras.getString("pname"));
  143.  
  144.  
  145. TextView pnText = (TextView) rootView.findViewById(R.id.textView2);
  146. pnText.setText( extras.getString("pText"));
  147.  
  148.  
  149.  
  150.  
  151. //Setup a listener we can use to swtich from the loading indicator to the Image once it's ready
  152. ImageLoadingListener listener = new ImageLoadingListener(){
  153.  
  154.  
  155.  
  156. @Override
  157. public void onLoadingStarted(String arg0, View arg1) {
  158. // TODO Auto-generated method stub
  159.  
  160. }
  161.  
  162. @Override
  163. public void onLoadingCancelled(String arg0, View arg1) {
  164. // TODO Auto-generated method stub
  165.  
  166. }
  167.  
  168. @Override
  169. public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
  170. // i/ndicator.setVisibility(View.INVISIBLE);
  171. // iconImg.setVisibility(View.VISIBLE);
  172. }
  173. @Override
  174. public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
  175. // TODO Auto-generated method stub
  176.  
  177. }
  178.  
  179. };
  180.  
  181. //Load the image and use our options so caching is handled.
  182. final ImageView iconImg = (ImageView) rootView.findViewById(R.id.imageView);
  183. imageLoader.displayImage( extras.getString("pImage"), iconImg, options, listener);
  184.  
  185.  
  186.  
  187. return rootView;
  188. }
  189. }
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement