Imitation Qiushibaike Android client source code

Imitation Qiushibaike Android client source code

Functional category: Social

Supported platforms: Android

Operating environment: Eclipse

Development language: Java

Development tool: Eclipse


Source code running screenshot

Source code snippet

  1. /**
  2. * Popular fragments
  3. * */  
  4. public   class HotFragment extends Fragment implements OnClickListener {
  5.    
  6.      private String hotUrl = Model.GANHUO;
  7.      private   int topMeunFlag = 1 ;
  8.      private View view;
  9.      private ImageView mTopImg;
  10.      private ImageView mSendAshamed;
  11.      private TextView mTopMenuOne, mTopMenuTwo, mTopMenuThree;
  12.      private MyListView myListView;
  13.      private LinearLayout mLinearLayout, load_progressBar;
  14.      private TextView HomeNoValue;
  15.      private HotFragmentCallBack mHotFragmentCallBack;
  16.      private MyJson myJson = new MyJson();
  17.      private List<ashamedinfo> list = new ArrayList<ashamedinfo>();
  18.      private MyListAdapter mAdapter = null ;
  19.      private Button ListBottem = null ;
  20.      private   int mStart = 0 ;
  21.      private   int mEnd = 5 ;
  22.      private String url = null ;
  23.      private   boolean flag = true ;
  24.      private   boolean loadflag = false ;
  25.      private   boolean listBottemFlag = true ;
  26.      private Context ctx;
  27.    
  28.      public View onCreateView(LayoutInflater inflater, ViewGroup container,
  29. Bundle savedInstanceState) {
  30. view = inflater.inflate(R.layout.frame_home, null );
  31. ctx = view.getContext();
  32. myListView = new MyListView(ctx);
  33. initView();
  34.          return view;
  35. }
  36.    
  37.      private   void initView() {
  38. load_progressBar = (LinearLayout) view
  39. .findViewById(R.id.load_progressBar);
  40. mLinearLayout = (LinearLayout) view.findViewById(R.id.HomeGroup);
  41. myListView.setLayoutParams( new LinearLayout.LayoutParams(
  42. LinearLayout.LayoutParams.MATCH_PARENT,
  43. LinearLayout.LayoutParams.WRAP_CONTENT));
  44. myListView.setDivider( null );
  45. mLinearLayout.addView(myListView);
  46. mTopImg = (ImageView) view.findViewById(R.id.Menu);
  47. mSendAshamed = (ImageView) view.findViewById(R.id.SendAshamed);
  48. mTopMenuOne = (TextView) view.findViewById(R.id.TopMenuOne);
  49. mTopMenuTwo = (TextView) view.findViewById(R.id.TopMenuTwo);
  50. mTopMenuThree = (TextView) view.findViewById(R.id.TopMenuThree);
  51. HomeNoValue = (TextView) view.findViewById(R.id.HomeNoValue);
  52. mTopImg.setOnClickListener( this );
  53. mSendAshamed.setOnClickListener( this );
  54. mTopMenuOne.setOnClickListener( this );
  55. mTopMenuTwo.setOnClickListener( this );
  56. mTopMenuThree.setOnClickListener( this );
  57. createTextColor();
  58.          switch (topMeunFlag) {
  59.          case   1 :
  60. mTopMenuOne.setTextColor(Color.WHITE);
  61. mTopMenuOne.setBackgroundResource(R.drawable.top_tab_active);
  62.              break ;
  63.          case   2 :
  64. mTopMenuTwo.setTextColor(Color.WHITE);
  65. mTopMenuTwo.setBackgroundResource(R.drawable.top_tab_active);
  66.              break ;
  67.          case   3 :
  68. mTopMenuThree.setTextColor(Color.WHITE);
  69. mTopMenuThree.setBackgroundResource(R.drawable.top_tab_active);
  70.              break ;
  71. }
  72. mAdapter = new MyListAdapter(ctx, list);
  73. ListBottem = new Button(ctx);
  74. ListBottem.setText( "Click to load more" );
  75. ListBottem.setOnClickListener( new View.OnClickListener() {
  76.              @Override  
  77.              public   void onClick(View v) {
  78.                  if (flag && listBottemFlag) {
  79. url = hotUrl + "start=" + mStart + "&end=" + mEnd;
  80. ThreadPoolUtils.execute( new HttpGetThread(hand, url));
  81. listBottemFlag = false ;
  82. } else   if (!listBottemFlag)
  83. Toast.makeText(ctx, "Loading..." , 1 ).show();
  84. }
  85. });
  86. myListView.addFooterView(ListBottem, null , false );
  87. ListBottem.setVisibility(View.GONE);
  88. myListView.setAdapter(mAdapter);
  89. myListView.setOnItemClickListener( new MainListOnItemClickListener());
  90. url = Model.GANHUO + "start=" + mStart + "&end=" + mEnd;
  91. ThreadPoolUtils.execute( new HttpGetThread(hand, url));
  92. myListView.setonRefreshListener( new OnRefreshListener() {
  93.    
  94.              @Override  
  95.              public   void onRefresh() {
  96.    
  97.                  if (loadflag == true ) {
  98. mStart = 0 ;
  99. mEnd = 5 ;
  100. url = hotUrl + "start=" + mStart + "&end=" + mEnd;
  101. ListBottem.setVisibility(View.GONE);
  102. ThreadPoolUtils.execute( new HttpGetThread(hand, url));
  103. loadflag = false ;
  104. } else {
  105. Toast.makeText(ctx, "Loading, please do not refresh repeatedly" , 1 ).show();
  106. }
  107.    
  108. }
  109. });
  110. }
  111.    
  112.      @Override  
  113.      public   void onClick(View arg0) {
  114.          int mID = arg0.getId();
  115.          switch (mID) {
  116.          case R.id.Menu:
  117. mHotFragmentCallBack.callback(R.id.Menu);
  118.              break ;
  119.          case R.id.SendAshamed:
  120. mHotFragmentCallBack.callback(R.id.SendAshamed);
  121.              break ;
  122.          case R.id.TopMenuOne:
  123. createTextColor();
  124. mTopMenuOne.setTextColor(Color.WHITE);
  125. mTopMenuOne.setBackgroundResource(R.drawable.top_tab_active);
  126.              if (topMeunFlag != 1 ) {
  127. hotUrl = Model.GANHUO;
  128. topMeunFlag = 1 ;
  129. createListModel();
  130. }
  131.              break ;
  132.          case R.id.TopMenuTwo:
  133. createTextColor();
  134. mTopMenuTwo.setTextColor(Color.WHITE);
  135. mTopMenuTwo.setBackgroundResource(R.drawable.top_tab_active);
  136.              if (topMeunFlag != 2 ) {
  137. hotUrl = Model.NENCAO;
  138. topMeunFlag = 2 ;
  139. createListModel();
  140. }
  141.              break ;
  142.          case R.id.TopMenuThree:
  143. createTextColor();
  144. mTopMenuThree.setTextColor(Color.WHITE);
  145. mTopMenuThree.setBackgroundResource(R.drawable.top_tab_active);
  146.              if (topMeunFlag != 3 ) {
  147. hotUrl = Model.WENZI;
  148. topMeunFlag = 3 ;
  149. createListModel();
  150. }
  151.              break ;
  152.          default :
  153.              break ;
  154. }
  155. }
  156.    
  157.      private   void createListModel() {
  158. ListBottem.setVisibility(View.GONE);
  159. mLinearLayout.setVisibility(View.GONE);
  160. load_progressBar.setVisibility(View.VISIBLE);
  161. loadflag = false ;
  162. mStart = 0 ;
  163. mEnd = 5 ;
  164. url = hotUrl + "start=" + mStart + "&end=" + mEnd;
  165. ThreadPoolUtils.execute( new HttpGetThread(hand, url));
  166. }
  167.    
  168.      private   class MainListOnItemClickListener implements OnItemClickListener {
  169.          public   void onItemClick(AdapterView<!--?--> arg0, View arg1, int arg2,
  170.                  long arg3) {
  171. Intent intent = new Intent(ctx, AshamedDetailActivity. class );
  172. Bundle bund = new Bundle();
  173. bund.putSerializable( "AshamedInfo" , list.get(arg2 - 1 ));
  174. intent.putExtra( "value" , ​​bund);
  175. startActivity(intent);
  176. }
  177. }
  178.    
  179.      @SuppressWarnings ( "deprecation" )
  180.      private   void createTextColor() {
  181. Drawable background = new BitmapDrawable();
  182. mTopMenuOne.setTextColor(Color.parseColor( "#815F3D" ));
  183. mTopMenuTwo.setTextColor(Color.parseColor( "#815F3D" ));
  184. mTopMenuThree.setTextColor(Color.parseColor( "#815F3D" ));
  185. mTopMenuOne.setBackgroundDrawable(background);
  186. mTopMenuTwo.setBackgroundDrawable(background);
  187. mTopMenuThree.setBackgroundDrawable(background);
  188. HomeNoValue.setVisibility(View.GONE);
  189. }
  190.    
  191.      public   void setCallBack(HotFragmentCallBack mHotFragmentCallBack) {
  192.          this .mHotFragmentCallBack = mHotFragmentCallBack;
  193. }
  194.    
  195.      public   interface HotFragmentCallBack {
  196.          public   void callback( int flag);
  197. }
  198.    
  199. Handler hand = new Handler() {
  200.          public   void handleMessage(android.os.Message msg) {
  201.              super .handleMessage(msg);
  202.              if (msg.what == 404 ) {
  203. Toast.makeText(ctx, "Address not found" , 1 ).show();
  204. listBottemFlag = true ;
  205. } else   if (msg.what == 100 ) {
  206. Toast.makeText(ctx, "Transfer failed" , 1 ).show();
  207. listBottemFlag = true ;
  208. } else   if (msg.what == 200 ) {
  209. String result = (String) msg.obj;
  210.                  if (result != null ) {
  211. List<ashamedinfo> newList = myJson.getAshamedList(result);
  212.                      if (newList != null ) {
  213.                          if (newList.size() == 5 ) {
  214. ListBottem.setVisibility(View.VISIBLE);
  215. mStart += 5 ;
  216. mEnd += 5 ;
  217. } else   if (newList.size() == 0 ) {
  218.                              if (list.size() == 0 )
  219. HomeNoValue.setVisibility(View.VISIBLE);
  220. ListBottem.setVisibility(View.GONE);
  221. Toast.makeText(ctx, "No more..." , 1 ).show();
  222. } else {
  223. ListBottem.setVisibility(View.GONE);
  224. }
  225.                          if (!loadflag) {
  226. list.removeAll(list);
  227. }
  228.                          for (AshamedInfo info : newList) {
  229. list.add(info);
  230. }
  231. listBottemFlag = true ;
  232. } else {
  233.                          if (list.size() == 0 )
  234. HomeNoValue.setVisibility(View.VISIBLE);
  235. }
  236. }
  237. mLinearLayout.setVisibility(View.VISIBLE);
  238. load_progressBar.setVisibility(View.GONE);
  239. myListView.onRefreshComplete();
  240. mAdapter.notifyDataSetChanged();
  241. loadflag = true ;
  242. }
  243. };
  244. };
  245.    
  246. }
  247. </ashamedinfo></ashamedinfo></ashamedinfo>

Download address: http://download..com/data/1971451

<<:  The big-screen phone bet is right! iOS has reversed its global market share

>>:  [Open Source & Sharing] Cocos Engine Chinese Official Website Tutorial Collection Order

Recommend

What licenses do e-commerce websites need?

The past 10 years have been the golden age of e-c...

226 products and commonly used website operation tools recommended

I have compiled some tools and useful websites, h...

What exactly is the “resonant copywriting” that leaders mention?

"Xiao Wang, your creative writing needs to r...

One out of every two adults has this real "secret"!

Studies have shown that bad breath has become the...