I got complete solution, i put filter method in custom adapter for multiple fields search functionality.
Note: for image loading i took lazy loading so you need ImageLoader.java, FileCache.java, Utils.java and MemoryCache.java.
Check bellow code.....
list_layout.xml ( layout folder )
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#ffffff" >
<EditText
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="search...."
android:paddingLeft="5dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="match_parent"
android:layout_below="@+id/et_search">
</ListView>
</RelativeLayout>
custom_row.xml ( layout folder )
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33B5E5" >
<ImageView
android:id="@+id/image_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="23dp"
android:layout_marginLeft="23dp"
android:layout_marginTop="23dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/image_view"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/image_view"
android:text="id"
android:textColor="#ffffff" />
<TextView
android:id="@+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txt_id"
android:layout_below="@+id/txt_id"
android:text="name"
android:textColor="#ffffff" />
</RelativeLayout>
put sample.json file in assets folder
sample.json
{
"sample":[
{
"id":"1",
"name":"nirav kalola",
"image":"http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg",
"description":"def"
},
{
"id":"2",
"name":"abc",
"image":"http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg",
"description":"abc"
},
{
"id":"3",
"name":"def",
"image":"http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg",
"description":"ghi"
},
{
"id":"55",
"name":"ghi",
"image":"http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg",
"description":"jkl"
},
{
"id":"5",
"name":"jkl",
"image":"http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg",
"description":"mno"
},
{
"id":"11",
"name":"mno",
"image":"http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg",
"description":"pqr"
},
{
"id":"10",
"name":"nirav007",
"image":"http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg",
"description":"stu"
}
]
}
ListActivity.java ( src folder )
public class ListActivity extends Activity {
private ListView listView;
private ProgressDialog progressDialog;
private List<SampleData> sampleData;
private ArrayList<SampleData> sampleList;
private SampleAdapter sampleAdapter;
private EditText etSearch;
ArrayList<SampleData> arraylist = new ArrayList<SampleData>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
listView=(ListView) findViewById(R.id.list_view);
BackGroundTask bt = new BackGroundTask();
bt.execute();
etSearch=(EditText) findViewById(R.id.et_search);
etSearch.setSingleLine(true);
etSearch.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
String text = etSearch.getText().toString().toLowerCase(Locale.getDefault());
sampleAdapter.filter(text);
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
}
private class BackGroundTask extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute(){
super.onPreExecute();
progressDialog = new ProgressDialog(ListActivity.this);
progressDialog.setCancelable(false);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
@Override
protected String doInBackground(Void... arg0) {
try {
JSONObject jsonObject = new JSONObject(loadJSONFromAsset());
JSONArray jsonArray = jsonObject.getJSONArray("sample");
sampleData=new ArrayList<SampleData>();
for (int i = 0; i < jsonArray.length(); i++)
{
JSONObject jsonObjectInside = jsonArray.getJSONObject(i);
String id = jsonObjectInside.getString("id");
String name = jsonObjectInside.getString("name");
String imagePath = jsonObjectInside.getString("image");
String description = jsonObjectInside.getString("description");
sampleData.add(new SampleData(id, name, imagePath, description));
Log.e("id",id+"");
Log.e("name",name+"");
Log.e("imagPath",imagePath+"");
Log.e("description",description+"");
}
handlePostsList(sampleData);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result){
super.onPostExecute(result);
progressDialog.dismiss();
}
}// End of Background AsyncTask
private void handlePostsList(final List<SampleData> sampleData) {
this.sampleData = sampleData;
runOnUiThread(new Runnable() {
public void run() {
try {
// logic for retrieve data first time in list view.
sampleList = new ArrayList<SampleData>();
for (int i = 0; i < sampleData.size(); i++) {
sampleList.add(new SampleData(sampleData.get(i).getId().toString(),sampleData.get(i).getName().toString(),sampleData.get(i).getImage().toString(),sampleData.get(i).getDescription().toString()));
}
sampleAdapter= new SampleAdapter(ListActivity.this, sampleList);
listView.setAdapter(sampleAdapter);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public class SampleAdapter extends BaseAdapter
{
Context context;
List<SampleData> sampleData=null;
ArrayList<SampleData> arraylist;
LayoutInflater inflater;
ImageLoader imageLoader;
public SampleAdapter(Context context, List<SampleData> sampleData) {
this.context = context;
this.sampleData = sampleData;
this.arraylist = new ArrayList<SampleData>();
this.arraylist.addAll(sampleData);
imageLoader=new ImageLoader(ListActivity.this);
}
public class ViewHolder {
TextView txtID,txtName,txtDescription;
ImageView image;
}
public int getCount() {
return sampleData.size();
}
public Object getItem(int position) {
return sampleData.get(position);
}
public long getItemId(int position) {
return sampleData.indexOf(getItem(position));
}
public View getView(final int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row, null);
holder = new ViewHolder();
holder.txtID = (TextView) convertView.findViewById(R.id.txt_id);
holder.txtName = (TextView) convertView.findViewById(R.id.txt_name);
holder.image = (ImageView) convertView.findViewById(R.id.image_view);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.txtID.setText(sampleData.get(position).getId());
holder.txtName.setText(sampleData.get(position).getName());
imageLoader.DisplayImage(sampleData.get(position).getImage(), holder.image);
// convertView.setOnClickListener(new OnClickListener() {
// Intent intent=null;
// @Override
// public void onClick(View v) {
// Log.e("description....",sampleData.get(position).getDescription()+"");
// intent=new Intent(ListActivity.this, DetailActivity.class);
// intent.putExtra("description", sampleData.get(position).getDescription());
// startActivity(intent);
// finish();
// }
// });
return convertView;
}
// Filter Class
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
sampleData.clear();
if (charText.length() == 0) {
sampleData.addAll(arraylist);
} else {
for (SampleData st : arraylist) {
if (st.getName().toLowerCase(Locale.getDefault()).contains(charText)) {
sampleData.add(st);
}else if (st.getId().toLowerCase(Locale.getDefault()).contains(charText)) {
sampleData.add(st);
}
else if (st.getName().toLowerCase(Locale.getDefault()).contains(charText)) {
sampleData.add(st);
}
}
}
notifyDataSetChanged();
}
}
public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getAssets().open("sample.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
}
SampleData.java ( src folder )
public class SampleData
{
private String id;
private String name;
private String image;
private String description;
public SampleData(String id, String name, String image, String description) {
super();
this.id = id;
this.name = name;
this.image = image;
this.description = description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
add following permissions in AndroidManifest.xml file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
thats it..
enjoy coding