用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

Fragment功能

2014-07-07 作者: 云代码会员举报

[android]代码库

	private GridView mGridView1,mGridView2;
	private ListView mLlistView3;
	private Button mApplication,mGame,mSubject;
	private ApplicationAdapter mApplicationAdapter;
	private GameAdapter mGameAdapter;
	private SubjectAdapter mSubjectAdapter;
	private List<Sorts> mAppList;
	private List<TopIcs> mTopIcsList;
	private Context mContext;
	private ProgressBar mProgressBar;
	private int selectBtn;
	private final int APPBTN=1;
	private final int GAME=2;
	private final int SUBJECT=3;
	String mApplicationName,mGameName,mSubjectName;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.category, container, false);
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		mContext=getView().getContext();
		initView();
		
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.application:
			getAppData(DataUrlKeys.APPLICATION_URL,"{}");
			mLlistView3.setVisibility(View.GONE);
			mGridView1.setVisibility(View.VISIBLE);
			selectBtn=APPBTN;
			break;
		case R.id.game:
			getAppData(DataUrlKeys.GAME_URL,"{}");
			mGridView1.setVisibility(View.VISIBLE);
			mLlistView3.setVisibility(View.GONE);
			selectBtn=GAME;
			break;
		case R.id.subject:
			getSubjectData(DataUrlKeys.TOPICLIST,"{\"index\":0,\"location\":\"homepage\",\"num\":4}");
			mGridView1.setVisibility(View.GONE);
			mLlistView3.setVisibility(View.VISIBLE);
			selectBtn=SUBJECT;
			break;

		}
	}
	public void initView(){
		mGridView1=(GridView) getView().findViewById(R.id.application_gridview);
		mLlistView3= (ListView) getView().findViewById(R.id.subject_ListView);
		mProgressBar=(ProgressBar) getView().findViewById(R.id.category_Progress);
		mApplication=(Button)getView(). findViewById(R.id.application);
		mGame=(Button) getView().findViewById(R.id.game);
		mSubject=(Button) getView().findViewById(R.id.subject);
		selectBtn=APPBTN;
		mApplication.setOnClickListener(this);
		mApplicationName=(String) mApplication.getText();
		mGame.setOnClickListener(this);
		mGameName=(String) mGame.getText();
		mSubject.setOnClickListener(this);
		mSubjectName=(String) mSubject.getText();
	//mApplicationName=(String) mApplication.getText();
	//	
		
		getAppData(DataUrlKeys.APPLICATION_URL,"{}");
		mGridView1.setOnItemClickListener(gridviewListener);
		mLlistView3.setOnItemClickListener(listviewListener);
	}
	/**
	 * 
	 * 方法说明:判断点击的是那个大标签
	 *
	 * @param selectBtn
	 * @return
	 */
	private String getSelectBtn(int selectBtn){
		String name="";
		switch (selectBtn) {
		case APPBTN:
			name="应用";
			break;
		case GAME:
			name="游戏";
			break;
		case SUBJECT:
			name="专题";
			break;
		}
		return name;
	}
	private void getAppData(String url,String params) {
		mProgressBar.setVisibility(View.VISIBLE);
		if(NetWorkUtil.isNetwork(mContext)){
		NetWorkUtil.getJsonData(getView().getContext(), url, params,new LoadJson() {
			
			@Override
			public void getJson(String data) {
				String	jsonData = data;
				if(!jsonData.equals("")){
//					System.out.println("json: "+jsonData);
					mApplicationAdapter=null;
					mAppList=	getListDataFromJsonData(jsonData);
//					System.out.println("applist: "+mAppList.toString());
					if(mAppList!=null){
						mApplicationAdapter=new ApplicationAdapter(mContext, mAppList);
						mGridView1.setAdapter(mApplicationAdapter);
						
						mProgressBar.setVisibility(View.GONE);
						
					}else{
						
					}
				}else{
					System.out.println("没有数据");
				}
			}
		});
		}else{
			System.out.println("没有网络连接");
		}
	}
	private void getSubjectData(String url,String params) {
		mProgressBar.setVisibility(View.VISIBLE);
		if(NetWorkUtil.isNetwork(mContext)){
		NetWorkUtil.getJsonData(getView().getContext(), url, params,new LoadJson() {
			
			@Override
			public void getJson(String data) {
				String	jsonData = data;
				if(!jsonData.equals("")){
//					System.out.println("json: "+jsonData);
					mSubjectAdapter=null;
					mTopIcsList=	getSubjectListDataFromJsonData(jsonData);
					System.out.println("mTopIcsList: "+mTopIcsList.toString());
					if(mTopIcsList!=null){
						mSubjectAdapter=new SubjectAdapter(mContext, mTopIcsList);
						mLlistView3.setAdapter(mSubjectAdapter);
						
						mProgressBar.setVisibility(View.GONE);
						
					}else{
						
					}
				}else{
					System.out.println("没有数据");
				}
			}
		});
		}else{
			System.out.println("没有网络连接");
		}
	}
	private List<Sorts> getListDataFromJsonData(String jsonData){
		Category cate=new Category();
		List<Sorts> app=null;
		Gson gson = new Gson();
		cate = gson.fromJson(jsonData, Category.class);
		app=cate.getmSorts();
		return app;
		
	}
	private List<TopIcs> getSubjectListDataFromJsonData(String jsonData){
		TopApp top=new TopApp();
		List<TopIcs> sub=null;
		Gson gson = new Gson();
		top = gson.fromJson(jsonData, TopApp.class);
		sub=top.getTopics();
		return sub;
		
	}
	
	private OnItemClickListener gridviewListener=new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Intent intent=new Intent(getActivity(),CategoryApplicationActivity.class);
			intent.putExtra("id", mAppList.get(arg2).getAssort_id());
			intent.putExtra("idName", "assort_id");
			String titleTag=getSelectBtn(selectBtn);
			intent.putExtra("titleName", titleTag+">"+mAppList.get(arg2).getAssort_name());
			startActivity(intent);
		}
	};
		
	private OnItemClickListener listviewListener=new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Intent intent=new Intent(getActivity(),CategoryApplicationActivity.class);
			intent.putExtra("id", mTopIcsList.get(arg2).getTopic_id());
			intent.putExtra("idName", "topic_id");
			String titleTag=getSelectBtn(selectBtn);
			intent.putExtra("titleName", titleTag+">"+mTopIcsList.get(arg2).getTitle());
			startActivity(intent);
		}
	};
	


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...