Java 用于筛选自定义listview元素的搜索筛选器

Java 用于筛选自定义listview元素的搜索筛选器,java,android,android-listview,android-filter,Java,Android,Android Listview,Android Filter,我所做的: 我能够通过JSON从webservice 并将其填充到listview 我已经实现了search filter来基于文本搜索元素 看法 我有什么问题:我会发布一系列快照来解释我的问题 快照1:我有列表视图显示列表中的一系列元素 快照2:现在,当我键入carl时,我的姓名将被过滤,只显示匹配的结果 快照3:现在删除搜索栏中的所有内容。。。。。我应该得到如快照1所示的显示,但这并没有发生 总体::一旦它被过滤,我就不能再使用它了。。。我必须重新编译整个项目 ListOfCo

我所做的

  • 我能够通过
    JSON
    webservice
    并将其填充到
    listview
  • 我已经实现了
    search filter
    来基于文本搜索元素 看法
我有什么问题:我会发布一系列快照来解释我的问题


  • 快照1:我有
    列表视图
    显示列表中的一系列元素
  • 快照2:现在,当我键入
    carl
    时,我的姓名将被过滤,只显示匹配的结果
  • 快照3:现在删除搜索栏中的所有内容。。。。。我应该得到如快照1所示的显示,但这并没有发生
  • 总体::一旦它被过滤,我就不能再使用它了。。。我必须重新编译整个项目


    ListOfContacts.java

    public class ListOfContacts extends Activity {
        // Declare Variables
        JSONObject jsonobject;
        JSONArray jsonarray;
        ListView listview;
        ListViewAdapter adapter;
        ProgressDialog mProgressDialog;
        ArrayList<HashMap<String, String>> arraylist;
        static String NAME = "rank";
        static String FLAG = "flag";
        EditText mEditText;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Get the view from listview_main.xml
            setContentView(R.layout.listview_main);
    
    
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listview);
            mEditText = (EditText) findViewById(R.id.inputSearch);
            // Execute DownloadJSON AsyncTask
            new DownloadJSON().execute();
    
    
        }
    
        // DownloadJSON AsyncTask
        class DownloadJSON extends AsyncTask<Void, Void, Void> {
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Create a progressdialog
                mProgressDialog = new ProgressDialog(ListOfContacts.this);
                // Set progressdialog title
                //mProgressDialog.setTitle("Fetching the information");
                // Set progressdialog message
                mProgressDialog.setMessage("Loading...");
                mProgressDialog.setIndeterminate(false);
                // Show progressdialog
                mProgressDialog.show();
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                // Create an array
                arraylist = new ArrayList<HashMap<String, String>>();
                // Retrieve JSON Objects from the given URL address
                jsonobject = JSONfunctions.getJSONfromURL("http://URL");
    
                try {
                    // Locate the array name in JSON
                    jsonarray = jsonobject.getJSONArray("restaurants");
    
                    for (int i = 0; i < jsonarray.length(); i++) {
                        HashMap<String, String> map = new HashMap<String, String>();
                        jsonobject = jsonarray.getJSONObject(i);
                        // Retrive JSON Objects
                        map.put(ListOfContacts.NAME, jsonobject.getString("Person_Name"));
                        map.put(ListOfContacts.FLAG, "http://54.218.73.244:7004/"+jsonobject.getString("Image_Name"));
    
    
    
                        // Set the JSON Objects into the array
                        arraylist.add(map);
                    }
                } catch (JSONException e) {
                    Log.e("Error", e.getMessage());
                    e.printStackTrace();
                }
                return null;
            }
    
            @Override
            protected void onPostExecute(Void args) {
                // Pass the results into ListViewAdapter.java
                adapter = new ListViewAdapter(ListOfContacts.this, arraylist);
                // Set the adapter to the ListView
                listview.setAdapter(adapter);
                // Close the progressdialog
    
                mEditText = (EditText) findViewById(R.id.inputSearch);
                mEditText.addTextChangedListener(new TextWatcher()
                {
    
                    public void afterTextChanged(Editable s)
                    {
    
                    }
    
                    public void beforeTextChanged(CharSequence s, int start,int count, int after)
                    {
    
                    }
    
                    public void onTextChanged(CharSequence s, int start,int before, int count)
                    {
    
                        ArrayList<HashMap<String, String>> arrayTemplist= new ArrayList<HashMap<String,String>>();
                        String searchString =mEditText.getText().toString();
                        for (int i = 0; i < arraylist.size(); i++)
                        {
                            String currentString =arraylist.get(i).get(ListOfContacts.NAME);
                            if (searchString.equalsIgnoreCase(currentString))
                            {
                                arrayTemplist.add(arraylist.get(i));
                            }
                        }
                        adapter = new ListViewAdapter(ListOfContacts.this, arrayTemplist);
                        listview.setAdapter(adapter);
                     }
                    });
                mProgressDialog.dismiss();
            }
        }
    }
    
    public class DataAcceptActivity extends Activity {
    
        Button submit;
        Button display;
        ProgressDialog pDialog;
        InputStream is;
        EditText name;
        ImageView imageView;
        EditText search;
    
        private static final int SELECT_PICTURE = 1;
        private String selectedImagePath;
    
        int[] image_array={R.drawable.index,R.drawable.image1,R.drawable.image5,R.drawable.image6,R.drawable.image7,R.drawable.image8,R.drawable.image9,R.drawable.image10};
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            submit = (Button) findViewById(R.id.SUBMIT_BUTTON_ID);
            name = (EditText) findViewById(R.id.editText1);
            imageView = (ImageView) findViewById(R.id.imageView1);
            display=(Button) findViewById(R.id.DISPLAY_BUTTON_ID);
    
            search=(EditText) findViewById(R.id.inputSearch);
    
            display.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Intent searchIntent=new Intent(DataAcceptActivity.this,ListOfContacts.class);
                    startActivity(searchIntent);
    
                }
            });
    
    
            submit.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    new MainTest().execute();
    
    
                }
            });
    
    
            imageView.setOnClickListener(new  OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
    
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
                }
            });
    
    
    
    
        }
    
    
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (resultCode == RESULT_OK) {
                if (requestCode == SELECT_PICTURE) {
                    Uri selectedImageUri = data.getData();
                    selectedImagePath = getPath(selectedImageUri);
                    System.out.println("Image Path : " + selectedImagePath);
                    imageView.setImageURI(selectedImageUri);
                }
            }
        }
    
        public String getPath(Uri uri) {
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
    
    
    
        /**
         * Method to post the image to the server.
         * U will have to change the url which will accept the image data.
         * @throws IOException 
         */
        public void postImageData() {
    
    
            try
            {
    
                Bitmap bitmapOrg = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
    
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost postRequest = new HttpPost("http://URL");
                MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                try{
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    bitmapOrg.compress(CompressFormat.JPEG, 75, bos);
                    byte[] data = bos.toByteArray();
                    ByteArrayBody bab = new ByteArrayBody(data, "image.jpg");
                    reqEntity.addPart("key", bab);
                    reqEntity.addPart("key1", new StringBody(name.getText().toString()));
                }
                catch(Exception e){
                    //Log.v("Exception in Image", ""+e);
                    reqEntity.addPart("picture", new StringBody(""));
                }
                postRequest.setEntity(reqEntity);       
                HttpResponse response = httpClient.execute(postRequest);
                BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                String sResponse;
                StringBuilder s = new StringBuilder();
                while ((sResponse = reader.readLine()) != null) {
                    s = s.append(sResponse);
                }
            }catch(Exception e){
                e.getStackTrace();
            }
    
    
        }
        public class MainTest extends AsyncTask<String, Integer, String> {
    
            @Override
            protected void onPreExecute() {
                pDialog = new ProgressDialog(DataAcceptActivity.this);
                pDialog.setMessage("Loading..");
                pDialog.setIndeterminate(true);
                pDialog.setCancelable(false);
                pDialog.show();
            }
    
            @Override
            protected String doInBackground(String... params) {
    
                postImageData();
    
                return null;
            }
    
            @Override
            protected void onPostExecute(String result) {
                // TODO Auto-generated method stub
    
                super.onPostExecute(result);
                // data=jobj.toString();
                pDialog.dismiss();
                Toast.makeText(getApplicationContext(), "File Uploaded", Toast.LENGTH_SHORT).show();
            }
    
        }
    
    
        class ImageAdapter extends BaseAdapter{
    
            Context cxt;
            public ImageAdapter(DataAcceptActivity dataAcceptActivity) {
                // TODO Auto-generated constructor stub
                this.cxt=dataAcceptActivity;
            }
    
            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return  image_array.length;
            }
    
            @Override
            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return position;
            }
    
            @Override
            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
    
                ImageView imageView ;
                if(convertView==null){
                    imageView=new ImageView(cxt);
                    imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    imageView.setPadding(15, 15, 15, 15);
                }else{
                    imageView=(ImageView) convertView;
                }
    
                imageView.setImageResource(image_array[position]);
                return imageView;
            }
    
        }
    
    }
    
    public class MainActivity extends Activity {
        // Declare Variables
        JSONObject jsonobject;
        JSONArray jsonarray;
        ListView listview;
        ListViewAdapter adapter;
        ProgressDialog mProgressDialog;
        ArrayList<HashMap<String, String>> arraylist;
    
        static String NAME = "rank";
        static String FLAG = "flag";
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Get the view from listview_main.xml
            setContentView(R.layout.listview_main);
    
    
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listview);
    
            // Execute DownloadJSON AsyncTask
            new DownloadJSON().execute();
        }
    
        // DownloadJSON AsyncTask
        private class DownloadJSON extends AsyncTask<Void, Void, Void> {
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Create a progressdialog
                mProgressDialog = new ProgressDialog(MainActivity.this);
                // Set progressdialog title
                //mProgressDialog.setTitle("Fetching the information");
                // Set progressdialog message
                mProgressDialog.setMessage("Loading...");
                mProgressDialog.setIndeterminate(false);
                // Show progressdialog
                mProgressDialog.show();
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                // Create an array
                arraylist = new ArrayList<HashMap<String, String>>();
                // Retrieve JSON Objects from the given URL address
                jsonobject = JSONfunctions.getJSONfromURL("http://URL");
    
                try {
                    // Locate the array name in JSON
                    jsonarray = jsonobject.getJSONArray("restaurants");
    
                    for (int i = 0; i < jsonarray.length(); i++) {
                        HashMap<String, String> map = new HashMap<String, String>();
                        jsonobject = jsonarray.getJSONObject(i);
                        // Retrive JSON Objects
                        map.put(MainActivity.NAME, jsonobject.getString("restaurantNAME"));;
                        map.put(MainActivity.FLAG, "http://url"+jsonobject.getString("restaurantIMAGE"));
    
    
                        // Set the JSON Objects into the array
                        arraylist.add(map);
                    }
                } catch (JSONException e) {
                    Log.e("Error", e.getMessage());
                    e.printStackTrace();
                }
                return null;
            }
    
            @Override
            protected void onPostExecute(Void args) {
                // Pass the results into ListViewAdapter.java
                adapter = new ListViewAdapter(MainActivity.this, arraylist);
                // Set the adapter to the ListView
                listview.setAdapter(adapter);
                // Close the progressdialog
                mProgressDialog.dismiss();
            }
        }
    }
    
    公共类联系人列表扩展活动{
    //声明变量
    JSONObject JSONObject;
    JSONArray JSONArray;
    列表视图列表视图;
    ListViewAdapter适配器;
    进程对话框;
    ArrayList ArrayList;
    静态字符串NAME=“rank”;
    静态字符串FLAG=“FLAG”;
    EditText-mEditText;
    @凌驾
    创建时的公共void(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    //从listview_main.xml获取视图
    setContentView(R.layout.listview_main);
    //在listview_main.xml中找到listview
    listview=(listview)findViewById(R.id.listview);
    mEditText=(EditText)findViewById(R.id.inputSearch);
    //执行下载JSON异步任务
    新建下载JSON().execute();
    }
    //下载JSON异步任务
    类DownloadJSON扩展异步任务{
    @凌驾
    受保护的void onPreExecute(){
    super.onPreExecute();
    //创建一个progressdialog
    mProgressDialog=新建进度对话框(ListOfContacts.this);
    //设置进程对话框标题
    //setTitle(“获取信息”);
    //设置进程对话框消息
    设置消息(“加载…”);
    mProgressDialog.setUndeterminate(false);
    //显示进度对话框
    mProgressDialog.show();
    }
    @凌驾
    受保护的Void doInBackground(Void…参数){
    //创建一个数组
    arraylist=新的arraylist();
    //从给定的URL地址检索JSON对象
    jsonobject=JSONfunctions.getJSONfromURL(“http://URL");
    试一试{
    //在JSON中找到数组名称
    jsonarray=jsonobject.getJSONArray(“餐厅”);
    for(int i=0;i
    dataacceptivity.java

    public class ListOfContacts extends Activity {
        // Declare Variables
        JSONObject jsonobject;
        JSONArray jsonarray;
        ListView listview;
        ListViewAdapter adapter;
        ProgressDialog mProgressDialog;
        ArrayList<HashMap<String, String>> arraylist;
        static String NAME = "rank";
        static String FLAG = "flag";
        EditText mEditText;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Get the view from listview_main.xml
            setContentView(R.layout.listview_main);
    
    
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listview);
            mEditText = (EditText) findViewById(R.id.inputSearch);
            // Execute DownloadJSON AsyncTask
            new DownloadJSON().execute();
    
    
        }
    
        // DownloadJSON AsyncTask
        class DownloadJSON extends AsyncTask<Void, Void, Void> {
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Create a progressdialog
                mProgressDialog = new ProgressDialog(ListOfContacts.this);
                // Set progressdialog title
                //mProgressDialog.setTitle("Fetching the information");
                // Set progressdialog message
                mProgressDialog.setMessage("Loading...");
                mProgressDialog.setIndeterminate(false);
                // Show progressdialog
                mProgressDialog.show();
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                // Create an array
                arraylist = new ArrayList<HashMap<String, String>>();
                // Retrieve JSON Objects from the given URL address
                jsonobject = JSONfunctions.getJSONfromURL("http://URL");
    
                try {
                    // Locate the array name in JSON
                    jsonarray = jsonobject.getJSONArray("restaurants");
    
                    for (int i = 0; i < jsonarray.length(); i++) {
                        HashMap<String, String> map = new HashMap<String, String>();
                        jsonobject = jsonarray.getJSONObject(i);
                        // Retrive JSON Objects
                        map.put(ListOfContacts.NAME, jsonobject.getString("Person_Name"));
                        map.put(ListOfContacts.FLAG, "http://54.218.73.244:7004/"+jsonobject.getString("Image_Name"));
    
    
    
                        // Set the JSON Objects into the array
                        arraylist.add(map);
                    }
                } catch (JSONException e) {
                    Log.e("Error", e.getMessage());
                    e.printStackTrace();
                }
                return null;
            }
    
            @Override
            protected void onPostExecute(Void args) {
                // Pass the results into ListViewAdapter.java
                adapter = new ListViewAdapter(ListOfContacts.this, arraylist);
                // Set the adapter to the ListView
                listview.setAdapter(adapter);
                // Close the progressdialog
    
                mEditText = (EditText) findViewById(R.id.inputSearch);
                mEditText.addTextChangedListener(new TextWatcher()
                {
    
                    public void afterTextChanged(Editable s)
                    {
    
                    }
    
                    public void beforeTextChanged(CharSequence s, int start,int count, int after)
                    {
    
                    }
    
                    public void onTextChanged(CharSequence s, int start,int before, int count)
                    {
    
                        ArrayList<HashMap<String, String>> arrayTemplist= new ArrayList<HashMap<String,String>>();
                        String searchString =mEditText.getText().toString();
                        for (int i = 0; i < arraylist.size(); i++)
                        {
                            String currentString =arraylist.get(i).get(ListOfContacts.NAME);
                            if (searchString.equalsIgnoreCase(currentString))
                            {
                                arrayTemplist.add(arraylist.get(i));
                            }
                        }
                        adapter = new ListViewAdapter(ListOfContacts.this, arrayTemplist);
                        listview.setAdapter(adapter);
                     }
                    });
                mProgressDialog.dismiss();
            }
        }
    }
    
    public class DataAcceptActivity extends Activity {
    
        Button submit;
        Button display;
        ProgressDialog pDialog;
        InputStream is;
        EditText name;
        ImageView imageView;
        EditText search;
    
        private static final int SELECT_PICTURE = 1;
        private String selectedImagePath;
    
        int[] image_array={R.drawable.index,R.drawable.image1,R.drawable.image5,R.drawable.image6,R.drawable.image7,R.drawable.image8,R.drawable.image9,R.drawable.image10};
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            submit = (Button) findViewById(R.id.SUBMIT_BUTTON_ID);
            name = (EditText) findViewById(R.id.editText1);
            imageView = (ImageView) findViewById(R.id.imageView1);
            display=(Button) findViewById(R.id.DISPLAY_BUTTON_ID);
    
            search=(EditText) findViewById(R.id.inputSearch);
    
            display.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Intent searchIntent=new Intent(DataAcceptActivity.this,ListOfContacts.class);
                    startActivity(searchIntent);
    
                }
            });
    
    
            submit.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    new MainTest().execute();
    
    
                }
            });
    
    
            imageView.setOnClickListener(new  OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
    
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
                }
            });
    
    
    
    
        }
    
    
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (resultCode == RESULT_OK) {
                if (requestCode == SELECT_PICTURE) {
                    Uri selectedImageUri = data.getData();
                    selectedImagePath = getPath(selectedImageUri);
                    System.out.println("Image Path : " + selectedImagePath);
                    imageView.setImageURI(selectedImageUri);
                }
            }
        }
    
        public String getPath(Uri uri) {
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
    
    
    
        /**
         * Method to post the image to the server.
         * U will have to change the url which will accept the image data.
         * @throws IOException 
         */
        public void postImageData() {
    
    
            try
            {
    
                Bitmap bitmapOrg = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
    
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost postRequest = new HttpPost("http://URL");
                MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                try{
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    bitmapOrg.compress(CompressFormat.JPEG, 75, bos);
                    byte[] data = bos.toByteArray();
                    ByteArrayBody bab = new ByteArrayBody(data, "image.jpg");
                    reqEntity.addPart("key", bab);
                    reqEntity.addPart("key1", new StringBody(name.getText().toString()));
                }
                catch(Exception e){
                    //Log.v("Exception in Image", ""+e);
                    reqEntity.addPart("picture", new StringBody(""));
                }
                postRequest.setEntity(reqEntity);       
                HttpResponse response = httpClient.execute(postRequest);
                BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                String sResponse;
                StringBuilder s = new StringBuilder();
                while ((sResponse = reader.readLine()) != null) {
                    s = s.append(sResponse);
                }
            }catch(Exception e){
                e.getStackTrace();
            }
    
    
        }
        public class MainTest extends AsyncTask<String, Integer, String> {
    
            @Override
            protected void onPreExecute() {
                pDialog = new ProgressDialog(DataAcceptActivity.this);
                pDialog.setMessage("Loading..");
                pDialog.setIndeterminate(true);
                pDialog.setCancelable(false);
                pDialog.show();
            }
    
            @Override
            protected String doInBackground(String... params) {
    
                postImageData();
    
                return null;
            }
    
            @Override
            protected void onPostExecute(String result) {
                // TODO Auto-generated method stub
    
                super.onPostExecute(result);
                // data=jobj.toString();
                pDialog.dismiss();
                Toast.makeText(getApplicationContext(), "File Uploaded", Toast.LENGTH_SHORT).show();
            }
    
        }
    
    
        class ImageAdapter extends BaseAdapter{
    
            Context cxt;
            public ImageAdapter(DataAcceptActivity dataAcceptActivity) {
                // TODO Auto-generated constructor stub
                this.cxt=dataAcceptActivity;
            }
    
            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return  image_array.length;
            }
    
            @Override
            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return position;
            }
    
            @Override
            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
    
                ImageView imageView ;
                if(convertView==null){
                    imageView=new ImageView(cxt);
                    imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    imageView.setPadding(15, 15, 15, 15);
                }else{
                    imageView=(ImageView) convertView;
                }
    
                imageView.setImageResource(image_array[position]);
                return imageView;
            }
    
        }
    
    }
    
    public class MainActivity extends Activity {
        // Declare Variables
        JSONObject jsonobject;
        JSONArray jsonarray;
        ListView listview;
        ListViewAdapter adapter;
        ProgressDialog mProgressDialog;
        ArrayList<HashMap<String, String>> arraylist;
    
        static String NAME = "rank";
        static String FLAG = "flag";
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Get the view from listview_main.xml
            setContentView(R.layout.listview_main);
    
    
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listview);
    
            // Execute DownloadJSON AsyncTask
            new DownloadJSON().execute();
        }
    
        // DownloadJSON AsyncTask
        private class DownloadJSON extends AsyncTask<Void, Void, Void> {
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Create a progressdialog
                mProgressDialog = new ProgressDialog(MainActivity.this);
                // Set progressdialog title
                //mProgressDialog.setTitle("Fetching the information");
                // Set progressdialog message
                mProgressDialog.setMessage("Loading...");
                mProgressDialog.setIndeterminate(false);
                // Show progressdialog
                mProgressDialog.show();
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                // Create an array
                arraylist = new ArrayList<HashMap<String, String>>();
                // Retrieve JSON Objects from the given URL address
                jsonobject = JSONfunctions.getJSONfromURL("http://URL");
    
                try {
                    // Locate the array name in JSON
                    jsonarray = jsonobject.getJSONArray("restaurants");
    
                    for (int i = 0; i < jsonarray.length(); i++) {
                        HashMap<String, String> map = new HashMap<String, String>();
                        jsonobject = jsonarray.getJSONObject(i);
                        // Retrive JSON Objects
                        map.put(MainActivity.NAME, jsonobject.getString("restaurantNAME"));;
                        map.put(MainActivity.FLAG, "http://url"+jsonobject.getString("restaurantIMAGE"));
    
    
                        // Set the JSON Objects into the array
                        arraylist.add(map);
                    }
                } catch (JSONException e) {
                    Log.e("Error", e.getMessage());
                    e.printStackTrace();
                }
                return null;
            }
    
            @Override
            protected void onPostExecute(Void args) {
                // Pass the results into ListViewAdapter.java
                adapter = new ListViewAdapter(MainActivity.this, arraylist);
                // Set the adapter to the ListView
                listview.setAdapter(adapter);
                // Close the progressdialog
                mProgressDialog.dismiss();
            }
        }
    }
    
    公共类数据可接受性扩展活动{
    按钮提交;
    按钮显示;
    ProgressDialog;
    输入流为;
    编辑文本名称;
    图像视图图像视图;
    编辑文本搜索;
    私有静态最终整数选择_PICTURE=1;
    私有字符串selectedImagePath;
    int[]image_数组={R.drawable.index,R.drawable.image1,R.drawable.image5,R.drawable.image6,R.drawable.image7,R.drawable.image8,R.drawable.image9,R.drawable.image10};
    @凌驾
    创建时受保护的void(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    submit=(按钮)findViewById(R.id.submit\u按钮\u id);
    name=(EditText)findViewById(R.id.editText1);
    imageView=(imageView)f