基本信息
源码名称:android 新闻客户端列表页 示例
源码大小:2.92M
文件格式:.rar
开发语言:Java
更新时间:2016-11-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package lty.newscol; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class MainActivity extends Activity implements OnClickListener{ private TextView tv_date; private TextView tv_month; private ListView lv; private String[] title; private String[] content; private List<HealthLayoutMessage> contentlist; private BaseAdapter adapter; private ImageView iv_more; List<Map<String, String>> moreList; private PopupWindow pwMyPopWindow;// popupwindow private ListView lvPopupList;// popupwindow对应的ListView private int NUM_OF_VISIBLE_LIST_ROWS = 5;//listview中栏目的数量 @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); initData(); initPopupWindow(); initotherview(); initviews(); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int p, long arg3) { // TODO Auto-generated method stub String url = contentlist.get(p).getUrl().toString(); Intent intent = new Intent(MainActivity.this,HealthNewsDetail.class); intent.putExtra("url", url); startActivity(intent); } }); } private List<HealthLayoutMessage> getMyData(){ List<HealthLayoutMessage> msgList = new ArrayList<HealthLayoutMessage>(); HealthLayoutMessage msg; title = getResources().getStringArray(R.array.lv_title); content = getResources().getStringArray(R.array.lv_content); /* * Tag标签:新闻的种类 * 1:慢病 * 2:免疫 * 3:流行病 * 4:保健 * */ msg = new HealthLayoutMessage(); msg.setTag(1); msg.setType(MyAdapter.LV_NO_PIC); msg.setTitle(title[0]); msg.setContent(content[0]); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(2); msg.setType(MyAdapter.LV_BIG_PIC); msg.setTitle(title[8]); msg.setPic(R.drawable.newspic1); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(1); msg.setType(MyAdapter.LV_NO_PIC); msg.setTitle(title[1]); msg.setContent(content[1]); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(3); msg.setType(MyAdapter.LV_LITTLE_PIC); msg.setTitle(title[2]); msg.setContent(content[2]); msg.setPic(R.drawable.newssquarepic1); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(4); msg.setType(MyAdapter.LV_NO_PIC); msg.setTitle(title[3]); msg.setContent(content[3]); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(4); msg.setType(MyAdapter.LV_NO_PIC); msg.setTitle(title[4]); msg.setContent(content[4]); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(2); msg.setType(MyAdapter.LV_LITTLE_PIC); msg.setTitle(title[5]); msg.setContent(content[5]); msg.setPic(R.drawable.newssquarepic2); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(1); msg.setType(MyAdapter.LV_BIG_PIC); msg.setTitle(title[9]); msg.setPic(R.drawable.newspic2); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(3); msg.setType(MyAdapter.LV_NO_PIC); msg.setTitle(title[6]); msg.setContent(content[6]); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); msg = new HealthLayoutMessage(); msg.setTag(3); msg.setType(MyAdapter.LV_NO_PIC); msg.setTitle(title[7]); msg.setContent(content[7]); msg.setUrl("http://news.fh21.com.cn/jksd/480509.html"); msgList.add(msg); return msgList; } private void initData() { moreList = new ArrayList<Map<String, String>>(); Map<String, String> map; map = new HashMap<String, String>(); map.put("share_key", "慢病"); moreList.add(map); map = new HashMap<String, String>(); map.put("share_key", "免疫"); moreList.add(map); map = new HashMap<String, String>(); map.put("share_key", "流行病"); moreList.add(map); map = new HashMap<String, String>(); map.put("share_key", "保健"); moreList.add(map); map = new HashMap<String, String>(); map.put("share_key", "所有资讯"); moreList.add(map); contentlist = new ArrayList<HealthLayoutMessage>(getMyData()); adapter = getAdapter(); } @SuppressLint("InflateParams") private void initPopupWindow() { LayoutInflater inflater = (LayoutInflater) this .getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.task_detail_popupwindow, null); lvPopupList = (ListView) layout.findViewById(R.id.lv_popup_list); pwMyPopWindow = new PopupWindow(layout); pwMyPopWindow.setFocusable(true); lvPopupList.setAdapter(new SimpleAdapter(MainActivity.this, moreList, R.layout.list_item_popupwindow, new String[] { "share_key" }, new int[] { R.id.tv_list_item })); lvPopupList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { contentlist.clear(); if(position == 4){ contentlist.addAll(getMyData()); } else{ contentlist.addAll(getMyData()); for(int i=0;i<contentlist.size();i ){ if(contentlist.get(i).getTag()!=(position 1)){ contentlist.remove(i); i--; } } } adapter.notifyDataSetChanged(); } }); // 设置popupwindow 的长宽 lvPopupList.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); pwMyPopWindow.setWidth(lvPopupList.getMeasuredWidth()); pwMyPopWindow.setHeight((lvPopupList.getMeasuredHeight() 6) * NUM_OF_VISIBLE_LIST_ROWS); // 设置背景 pwMyPopWindow.setBackgroundDrawable(this.getResources().getDrawable( R.drawable.bitmap_book_read_chapterlist_repeat)); pwMyPopWindow.setOutsideTouchable(true);//设置popupwindow 点击外面消失 } private void initotherview() { // TODO Auto-generated method stub iv_more = (ImageView)findViewById(R.id.health_news_more_content); iv_more.setOnClickListener(this); } private BaseAdapter getAdapter(){ return new MyAdapter(this, contentlist); } private void initviews() { // TODO Auto-generated method stub String[] monthname = getResources().getStringArray(R.array.Month); tv_date = (TextView)findViewById(R.id.health_news_date); tv_month = (TextView)findViewById(R.id.health_news_month); lv = (ListView)findViewById(R.id.health_news_lv); lv.setAdapter(adapter); /* *修改日期信息 * */ Calendar c = Calendar.getInstance();//可以对每个时间域单独修改 int month_index = c.get(Calendar.MONTH); String date = String.valueOf(c.get(Calendar.DATE)); if(date.length()<2) date = "0" date; tv_date.setText(date); tv_month.setText(monthname[month_index]); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.health_news_more_content: if (pwMyPopWindow.isShowing()) { pwMyPopWindow.dismiss();// 鍏抽棴 } else { pwMyPopWindow.showAsDropDown(iv_more);// 鏄剧ず } } } }