Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as Java by tuan ( 7 years ago )
package com.example.vuhuu.tuanprj.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.ViewFlipper;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.vuhuu.tuanprj.R;
import com.example.vuhuu.tuanprj.activity.Activity_Main;
import com.example.vuhuu.tuanprj.adapter.CustomGridView_Home;
import com.example.vuhuu.tuanprj.adapter.CustomGridView_Homer;
import com.example.vuhuu.tuanprj.inteface.fragmentInterface;
import com.example.vuhuu.tuanprj.model.Book;
import com.example.vuhuu.tuanprj.model.Category;
import com.example.vuhuu.tuanprj.ultil.ChecConnection;
import com.example.vuhuu.tuanprj.ultil.HowkSQLiteHelper;
import com.example.vuhuu.tuanprj.ultil.ServerURLs;
import com.example.vuhuu.tuanprj.ultil.VolleySingleton;
import com.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.facebook.FacebookSdk.getApplicationContext;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment_home extends Fragment {
private String TAG = Activity_Main.TAG;
private View view;
private ViewFlipper viewFlipper;
private Spinner spnCategory;
private GridView Gv;
private CustomGridView_Homer CusGVH;
private ArrayList<Book> Books;
private ArrayList<Category> categorys;
private int id = 0;
private String categoryname = "";
private HowkSQLiteHelper howkSQLiteHelper;
protected fragmentInterface listener;
public fragment_home() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_fragment_home, container, false);
AnhXa();
DatQuangCao();
howkSQLiteHelper.CheckDatabase();
GetCategory();
return view;
}
private void GetCategory() {
categorys = howkSQLiteHelper.getListCategory();
categorys.add(0,new Category(0,"Tat ca"));
List<String> list = new ArrayList<>();//list chua danh sach category
for(int i =0;i<categorys> adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item,list);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
spnCategory.setAdapter(adapter);
spnCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
GetProduct(spnCategory.getSelectedItemPosition());
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
private void GetProduct(final int selectedItemPosition) {
Log.d(TAG,"GetProduct");
Books.clear();
Books = howkSQLiteHelper.getListBook(selectedItemPosition);
Log.d(TAG,"Books:"+Books.get(0).toString());
CusGVH.notifyDataSetChanged();
}
private void DatQuangCao() {
/*
* Xu li code chay slide quang cao
* res/anim/slide_in_right.xml
* res/anim/slide_out_right.xml
* */
ArrayList<String> mangquangcao = new ArrayList<>();
mangquangcao.add("https://tinhte.cdnforo.com/store/2014/08/2572609_Hinh_2.jpg");
mangquangcao.add("https://cdn.mediamart.vn/News/mua-vaio-rinh-qua-xperia-cung-media-mart-924201273231am.jpg");
mangquangcao.add("http://www.thongtincongnghe.com/sites/default/files/images/2012/1/13/img-1326420488-2.jpg");
for(int i = 0; i < mangquangcao xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed>();
Books = new ArrayList<>();
howkSQLiteHelper = new HowkSQLiteHelper(getActivity());
Gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listener.onOpenBookInfo(Books.get(position).bookid+"");
}
});
CusGVH = new CustomGridView_Homer(getActivity(),Books);
String arr[] = {"1","2"};
ArrayAdapter<String> da = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,arr);
Gv.setAdapter(CusGVH);
}
@Override
public void onAttach(Context context) {
//kiem tra xem Activity_Main da implement Interface hay chua
super.onAttach(context);
if (context instanceof fragmentInterface){
listener= (fragmentInterface) context;
} else {
throw new RuntimeException(context.toString() + " must implement onViewSelected");
}
}
}
Revise this Paste