SHOW:
|
|
- or go back to the newest paste.
1 | package info.androidhive.slidingmenu; | |
2 | ||
3 | import id.pratamawijaya.kamuskomputer.ArtiActivity; | |
4 | import id.pratamawijaya.kamuskomputer.DatabaseHelper; | |
5 | import id.pratamawijaya.kamuskomputer.Kamus; | |
6 | ||
7 | ||
8 | import java.util.List; | |
9 | ||
10 | import android.app.Activity; | |
11 | import android.app.Fragment; | |
12 | import android.content.Intent; | |
13 | import android.os.Bundle; | |
14 | import android.text.Editable; | |
15 | import android.text.TextWatcher; | |
16 | import android.view.LayoutInflater; | |
17 | import android.view.View; | |
18 | import android.view.ViewGroup; | |
19 | import android.view.Window; | |
20 | import android.widget.AdapterView; | |
21 | import android.widget.ArrayAdapter; | |
22 | import android.widget.EditText; | |
23 | import android.widget.ListView; | |
24 | import android.widget.AdapterView.OnItemClickListener; | |
25 | ||
26 | - | public class PagesFragment extends Fragment{ |
26 | + | public class PagesFragment extends Fragment implements TextWatcher, |
27 | - | |
27 | + | OnItemClickListener{ |
28 | - | public PagesFragment(){} |
28 | + | |
29 | - | |
29 | + | private EditText search; |
30 | - | @Override |
30 | + | private ListView lv; |
31 | private DatabaseHelper dbHelper; | |
32 | - | Bundle savedInstanceState) { |
32 | + | private ArrayAdapter<Kamus> adapter; |
33 | - | |
33 | + | private List<Kamus> listKamus; |
34 | ||
35 | - | |
35 | + | public PagesFragment(){} |
36 | ||
37 | @Override | |
38 | public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
39 | - | |
39 | + | Bundle savedInstanceState) { |
40 | - | |
40 | + | |
41 | - | |
41 | + | |
42 | - | private class database extends Activity implements TextWatcher, |
42 | + | |
43 | - | OnItemClickListener { |
43 | + | lv = (ListView) rootView.findViewById(R.id.lv_data); |
44 | - | private EditText search; |
44 | + | lv.setEmptyView(findViewById(R.id.empty)); |
45 | - | private ListView lv; |
45 | + | search = (EditText) rootView.findViewById(R.id.search); |
46 | - | private DatabaseHelper dbHelper; |
46 | + | |
47 | - | private ArrayAdapter<Kamus> adapter; |
47 | + | dbHelper = DatabaseHelper.getInstance(getActivity()); |
48 | - | private List<Kamus> listKamus; |
48 | + | |
49 | - | |
49 | + | setData(); |
50 | - | protected void onCreate(Bundle savedInstanceState){ |
50 | + | |
51 | - | super.onCreate(savedInstanceState); |
51 | + | search.addTextChangedListener(this); |
52 | - | setContentView(R.layout.fragment_pages); |
52 | + | lv.setOnItemClickListener(this); |
53 | - | requestWindowFeature(Window.FEATURE_NO_TITLE); |
53 | + | |
54 | - | lv = (ListView) findViewById(R.id.lv_data); |
54 | + | |
55 | - | lv.setEmptyView(findViewById(R.id.empty)); |
55 | + | |
56 | - | search = (EditText) findViewById(R.id.search); |
56 | + | |
57 | ||
58 | - | dbHelper = DatabaseHelper.getInstance(this); |
58 | + | private void setData() { |
59 | // TODO Auto-generated method stub | |
60 | - | setData(); |
60 | + | listKamus = dbHelper.getAllKamus(); |
61 | ||
62 | - | search.addTextChangedListener(this); |
62 | + | adapter = new ArrayAdapter<Kamus>(this, |
63 | - | lv.setOnItemClickListener(this); |
63 | + | android.R.layout.simple_expandable_list_item_1, listKamus); |
64 | - | } |
64 | + | lv.setAdapter(adapter); |
65 | } | |
66 | - | private void setData() { |
66 | + | |
67 | - | // TODO Auto-generated method stub |
67 | + | |
68 | - | listKamus = dbHelper.getAllKamus(); |
68 | + | |
69 | @Override | |
70 | - | adapter = new ArrayAdapter<Kamus>(this, |
70 | + | public void afterTextChanged(Editable arg0) |
71 | - | android.R.layout.simple_expandable_list_item_1, listKamus); |
71 | + | { |
72 | - | lv.setAdapter(adapter); |
72 | + | |
73 | - | } |
73 | + | |
74 | @Override | |
75 | - | |
75 | + | public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, |
76 | int arg3) | |
77 | - | @Override |
77 | + | { |
78 | - | public void afterTextChanged(Editable arg0) |
78 | + | |
79 | - | { |
79 | + | |
80 | - | } |
80 | + | @Override |
81 | public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) | |
82 | - | @Override |
82 | + | { |
83 | - | public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, |
83 | + | adapter.getFilter().filter(s.toString()); |
84 | - | int arg3) |
84 | + | |
85 | - | { |
85 | + | |
86 | - | } |
86 | + | @Override |
87 | public void onItemClick(AdapterView<?> arg0, View arg1, int position, | |
88 | - | @Override |
88 | + | long id) |
89 | - | public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) |
89 | + | { |
90 | - | { |
90 | + | // TODO Auto-generated method stub |
91 | - | adapter.getFilter().filter(s.toString()); |
91 | + | Bundle b = new Bundle(); |
92 | - | } |
92 | + | b.putString("istilah", adapter.getItem(position).getIstilah()); |
93 | b.putString("arti", adapter.getItem(position).getArti()); | |
94 | - | @Override |
94 | + | |
95 | - | public void onItemClick(AdapterView<?> arg0, View arg1, int position, |
95 | + | Intent i = new Intent(this, ArtiActivity.class); |
96 | - | long id) |
96 | + | i.putExtras(b); |
97 | - | { |
97 | + | getActivity().startActivity(i); |
98 | - | // TODO Auto-generated method stub |
98 | + | |
99 | - | Bundle b = new Bundle(); |
99 | + | |
100 | - | b.putString("istilah", adapter.getItem(position).getIstilah()); |
100 | + |