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