lawang code

lawang Code


Tanyakan kode disini

Gan Bisa Bantu Ane buat Filter pada CustumListview, Ini Code Ane help..

ditanyakan oleh ervan aryantika 3 tahun yang lalu

Code on Mainactivity

public class Pencarian extends Activity implements TextWatcher {
AutoCompleteTextView edit;
GridView Gv;
String[] daftarkata;
Menu menu;
DBhelper dbHelper;
private List<ModelGambar> gambarList = new ArrayList<ModelGambar>();
private AdapterGambar adapterGambar;
public static Activity fa;
private System system;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pencarian);
    fa = this;
    dbHelper = new DBhelper(this);
    try {
        dbHelper.createDataBase();
    } catch (Exception e) {
        // ODO: handle exception
    }
    Gv = (GridView)findViewById(R.id.gridView1);
    getimage();
    getdaftarkata();
    edit = (SearchView) findViewById(R.id.edit);
    edit.addTextChangedListener((new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {    

        }
        @Override
        public void afterTextChanged(Editable s) {

        }
    }));
}

public void getimage(){
    byte[] byteImage = null;
    Cursor cur = dbHelper.getgambarkata();
    cur.moveToFirst();
    AdapterGambar adapterGambar = new AdapterGambar(this,gambarList);
    Gv.setAdapter(adapterGambar);

    if (cur.moveToFirst()) {
        do {
            ModelGambar obj = new ModelGambar();
            //Lakukan di setiap perulangan
            byteImage = cur.getBlob(cur.getColumnIndex("Gambar"));
            String Id_gambar = cur.getString(cur.getColumnIndex("Id_gambar"));
            String Kata = cur.getString(cur.getColumnIndex("Kata"));

            obj.setId_gambar(Id_gambar);
            obj.setKata(Kata);
            obj.setGambar(byteImage);
            Log.d("Kata", Kata);
            gambarList.add(obj);
           // Toast.makeText(getApplicationContext(), Kata, Toast.LENGTH_SHORT);
            //end perulangan
        } while (cur.moveToNext());
    }








Code On my Model class

public class ModelGambar {
private String Id_kata, Kata, Id_gambar;
private byte[] Gambar;

public ModelGambar(){}




public ModelGambar(String Id_kata, String Kata, String Id_gambar, byte[] Gambar){
    this.Id_kata=Id_kata;
    this.Kata=Kata;
    this.Id_gambar=Id_gambar;
    this.Gambar=Gambar;

}
public String getId_kata(){return Id_kata;}

public void setId_kata(String val) { Id_kata = val;    }

public String getKata(){return Kata;}

public void setKata(String val) {Kata=val;}

public String getId_gambar(){return Id_gambar;}

public void setId_gambar(String val) {Id_gambar=val;}

public byte[] getGambar(){return Gambar;}

public void setGambar(byte[] val) {Gambar=val;}







Code On my Adapter Class

public class AdapterGambar  extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<ModelGambar> gambarList;

public AdapterGambar(Activity activity, List<ModelGambar> gambarList){
    this.activity = activity;
    this.gambarList = gambarList;

}
@Override
public int getCount() {
    return gambarList.size();
}

@Override
public Object getItem(int position) {
    return gambarList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (inflater==null)
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null)
        convertView = inflater.inflate(R.layout.cellgrid,null);

    ImageView gambar = (ImageView) convertView.findViewById(R.id.imageViewGambar);
    TextView keterangan = (TextView) convertView.findViewById(R.id.keterangan);

    ModelGambar mg = gambarList.get(position);

    gambar.setImageBitmap(BitmapFactory.decodeByteArray(mg.getGambar(), 0,
            mg.getGambar().length));

    keterangan.setText(mg.getKata());

    return convertView;
}



Menampilkan 1-6 dari 6 hasil
handita okviyanto menjawab 3 tahun yang lalu :

Filternya apa dlu ni gan? buat nyari data apa aja?


ervan aryantika menjawab 3 tahun yang lalu :

filter pencarian seperti gambar ini gan : image alt


ervan aryantika menjawab 3 tahun yang lalu :

bisa bantu bwt? code ane sperti diatas yg ane posting,,


handita okviyanto menjawab 3 tahun yang lalu :

bukannya udah jelas ya gan tutorial di http://www.androidbegin.com/tutorial/android-search-listview-using-filter/

gak ngertinya gmana dengan code agan?

gini pake

public class AdapterGambar  extends BaseAdapter implements Filterable {
....

@Override
public Filter getFilter() {

    Filter filter = new Filter() {

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {


            notifyDataSetChanged();
        }

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {

            FilterResults results = new FilterResults();
            ArrayList<ModulGambar> FilteredModelGambar = new ArrayList<ModelGambar>();

            constraint = constraint.toString().toLowerCase();
            for (int i = 0; i < gambarList.size(); i++) {
                ModelGambar gambar= gambarList.get(i);
                if (gambar.getKata().toLowerCase().startsWith(constraint.toString()))  {
                    FilteredModelGambar .add(gambar);
                }
            }

            results.count = FilteredModelGambar .size();
            results.values = FilteredModelGambar ;
            Log.e("VALUES", results.values.toString());

            return results;
        }
    };

    return filter;
}

}


ervan aryantika menjawab 3 tahun yang lalu :

makasi gan


Sopiyan71 menjawab 3 tahun yang lalu :

kalo di sini kan http://www.androidbegin.com/tutorial/android-search-listview-using-filter/ saat di klik keluarnya berupa tulisan, kalo pada saat di klik terus keluar kelas baru atau webview, berupa gambar dan informasi bagaimana gan. sebab pada kelas baru mau ane bikin koding lagi. mohon bantuannya gan


Anda harus login terlebih dahulu untuk memberikan komentar

Recent Tag

X 6
X 48
X 14
X 10
X 1
X 5
X 4
X 13
X 10

Bantuan

Help

Feedback

Help