Java Code Examples for android.widget.SimpleAdapter#notifyDataSetChanged()

The following examples show how to use android.widget.SimpleAdapter#notifyDataSetChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmailListActivity.java    From androidmooc-clase1 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
	EditText editTextEmail = (EditText)findViewById(R.id.editTextEmail);
	String email = editTextEmail.getText().toString();
	
	if (!email.trim().equals("")) {
		if (Patterns.EMAIL_ADDRESS.matcher(email).matches()) {			
			HashMap<String, String> element = new HashMap<String, String>();
			String date = new SimpleDateFormat("dd/MM/yyyy HH:mm", 
										       Locale.getDefault())
														.format(Calendar.getInstance().getTime());
			element.put(EMAIL, email);
			element.put(DATE_ADDED, "agregado " + date);
			emails.add(element);
			
			final SimpleAdapter adapter = (SimpleAdapter) getListAdapter();
			adapter.notifyDataSetChanged();
		} else {
			Toast.makeText(getApplicationContext(), 
						   getResources().getString(R.string.txt_email_error), 
						   Toast.LENGTH_SHORT).show();
		}
	}
}
 
Example 2
Source File: EmailListActivity.java    From androidmooc-clase1 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
	EditText editTextEmail = (EditText)findViewById(R.id.editTextEmail);
	String email = editTextEmail.getText().toString();
	
	if (!email.trim().equals("")) {
		//if (Patterns.EMAIL_ADDRESS.matcher(email).matches()) {			
			HashMap<String, String> element = new HashMap<String, String>();
			String date = new SimpleDateFormat("dd/MM/yyyy HH:mm", 
										       Locale.getDefault())
														.format(Calendar.getInstance().getTime());
			element.put(EMAIL, email);
			element.put(DATE_ADDED, "agregado " + date);
			emails.add(element);
			
			final SimpleAdapter adapter = (SimpleAdapter) getListAdapter();
			adapter.notifyDataSetChanged();
			/*
		} else {
			Toast.makeText(getApplicationContext(), 
						   getResources().getString(R.string.txt_email_error), 
						   Toast.LENGTH_SHORT).show();
		}
		*/
	}
}
 
Example 3
Source File: InputtipsActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 输入提示结果的回调
 * @param tipList
 * @param rCode
    */
@Override
public void onGetInputtips(final List<Tip> tipList, int rCode) {
       if (rCode == AMapException.CODE_AMAP_SUCCESS) {
           List<HashMap<String, String>> listString = new ArrayList<HashMap<String, String>>();
           if(tipList != null) {
           	int size = tipList.size();
			for (int i = 0; i < size; i++) {
				Tip tip = tipList.get(i);
				if(tip != null) {
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("name", tipList.get(i).getName());
					map.put("address", tipList.get(i).getDistrict());
					listString.add(map);
				}
			}
			SimpleAdapter aAdapter = new SimpleAdapter(getApplicationContext(), listString, R.layout.item_layout,
					new String[]{"name", "address"}, new int[]{R.id.poi_field_id, R.id.poi_value_id});

			minputlist.setAdapter(aAdapter);
			aAdapter.notifyDataSetChanged();
		}

       } else {
		ToastUtil.showerror(this.getApplicationContext(), rCode);
	}
	
}
 
Example 4
Source File: FlightCityThreeCodesAPIActivity.java    From styT with Apache License 2.0 5 votes vote down vote up
public void onSuccess(API api, int action, Map<String, Object> result) {
	switch (action) {
		case Flight.ACTION_QUERY_THREE_CODE: {
			ArrayList<Map<String, Object>> res = ResHelper.forceCast(result.get("result"));
			if (res == null) {
				return;
			}
			SimpleAdapter adapter = new SimpleAdapter(this, res, R.layout.view_flight_three_code_list_item,
					new String[]{"airPortName", "cityCode", "cityName", "threeCode"},
					new int[]{R.id.tvAirPortName, R.id.tvCityCode, R.id.tvCityName, R.id.tvThreeCode});
			getListView().setAdapter(adapter);
			adapter.notifyDataSetChanged();
		} break;
	}
}
 
Example 5
Source File: QueryAllCurrency.java    From styT with Apache License 2.0 5 votes vote down vote up
public void onSuccess(API api, int action, Map<String, Object> result) {
	ArrayList<Map<String, Object>> res = ResHelper.forceCast(result.get("result"));
	SimpleAdapter adapter = new SimpleAdapter(this, res, R.layout.view_exchange_currency_item,
			new String[]{"code", "name"}, new int[]{R.id.tvCurrencyCode, R.id.tvCurrencyName});
	lvResult.setAdapter(adapter);
	adapter.notifyDataSetChanged();
}
 
Example 6
Source File: QueryAllCurrency.java    From stynico with MIT License 5 votes vote down vote up
public void onSuccess(API api, int action, Map<String, Object> result) {
    ArrayList<Map<String, Object>> res = forceCast(result.get("result"));
    SimpleAdapter adapter = new SimpleAdapter(this, res, R.layout.view_exchange_currency_item,
            new String[]{"code", "name"}, new int[]{R.id.tvCurrencyCode, R.id.tvCurrencyName});
    lvResult.setAdapter(adapter);
    adapter.notifyDataSetChanged();
}
 
Example 7
Source File: MineFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    StatService.onResume(this);
    if(!TextUtils.isEmpty(pathImage)){
        try {
            imageItem.ensureCapacity(imageItem.size()+1);
            Bitmap addbmp= ImageUtil.revitionImageSize(pathImage);
            byte[] bytes = CommentUtil.Bitmap2Bytes(addbmp);
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("itemImage", addbmp);
            imageItem.add(gridviewClickItemPosition, map);

            //addPhowoWall
            addPhotoWall(gridviewClickItemPosition,bytes);
            simpleAdapter = new SimpleAdapter(getActivity(), imageItem, R.layout.griditem_addpic, new String[] { "itemImage"}, new int[] { R.id.imageView1});
            simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
                @Override
                public boolean setViewValue(View view, Object data,
                                            String textRepresentation) {
                    // TODO Auto-generated method stub
                    if(view instanceof ImageView && data instanceof Bitmap){
                        ImageView i = (ImageView)view;
                        i.setImageBitmap((Bitmap) data);
                        return true;
                    }
                    return false;
                }
            });
            gridView1.setAdapter(simpleAdapter);
            simpleAdapter.notifyDataSetChanged();
            //刷新后释放防止手机休眠后自动添加
            pathImage = null;
        }catch (IOException e){
            e.printStackTrace();
        }


    }
}
 
Example 8
Source File: AddRecruitActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    StatService.onResume(this);//统计activity页面
    if(!TextUtils.isEmpty(pathImage)){

        imageItem.ensureCapacity(imageItem.size()+1);

        Bitmap addbmp=BitmapFactory.decodeFile(pathImage);
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("itemImage", addbmp);
        imageItem.add(gridviewClickItemPosition, map);

        simpleAdapter = new SimpleAdapter(this, imageItem, R.layout.griditem_addpic, new String[] { "itemImage"}, new int[] { R.id.imageView1});
        simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Object data,
                                        String textRepresentation) {
                // TODO Auto-generated method stub
                if(view instanceof ImageView && data instanceof Bitmap){
                    ImageView i = (ImageView)view;
                    i.setImageBitmap((Bitmap) data);
                    return true;
                }
                return false;
            }
        });
        gridView1.setAdapter(simpleAdapter);
        simpleAdapter.notifyDataSetChanged();
        //刷新后释放防止手机休眠后自动添加
        pathImage = null;
    }
}
 
Example 9
Source File: AddNewsActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    StatService.onResume(this);//统计activity页面
    if(!TextUtils.isEmpty(pathImage)){
        //Toast.makeText(this,pathImage,Toast.LENGTH_LONG).show();
        Log.d("onResume", "in onResume pathImage = " + pathImage);

        imageItem.ensureCapacity(imageItem.size()+1);

        Bitmap addbmp=BitmapFactory.decodeFile(pathImage);
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("itemImage", addbmp);
        imageItem.add(gridviewClickItemPosition,map);
        simpleAdapter = new SimpleAdapter(this,
                imageItem, R.layout.griditem_addpic,
                new String[] { "itemImage"}, new int[] { R.id.imageView1});
        simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Object data,
                                        String textRepresentation) {
                // TODO Auto-generated method stub
                if(view instanceof ImageView && data instanceof Bitmap){
                    ImageView i = (ImageView)view;
                    i.setImageBitmap((Bitmap) data);
                    return true;
                }
                return false;
            }
        });
        gridView1.setAdapter(simpleAdapter);
        simpleAdapter.notifyDataSetChanged();
        //刷新后释放防止手机休眠后自动添加
        pathImage = null;
    }
}
 
Example 10
Source File: RepoTask.java    From Bitocle with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(Boolean result) {
    if (result) {
        RAction action = new RAction(context);
        try {
            action.openDatabase(true);
        } catch (SQLException s) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_error);
            fragment.setContentShown(true);
            return;
        }

        List<Repo> repos = action.listRepos();
        Collections.sort(repos);

        List<Map<String, String>> autoList = new ArrayList<Map<String, String>>();

        list.clear();
        autoList.clear();
        for (Repo r : repos) {
            list.add(
                    new RepoItem(
                            r.getName(),
                            r.getDate(),
                            r.getDescription(),
                            r.getLang(),
                            r.getStar(),
                            r.getFork(),
                            r.getOwner(),
                            r.getGit()
                    )
            );
            Map<String, String> map = new HashMap<String, String>();
            map.put("owner", r.getOwner());
            map.put("name", r.getName());
            autoList.add(map);
        }
        action.closeDatabase();

        SimpleAdapter autoAdapter = new SimpleAdapter(
                context,
                autoList,
                R.layout.auto_item,
                new String[] {"owner", "name"},
                new int[] {R.id.auto_item_owner, R.id.auto_item_name}
        );
        autoAdapter.notifyDataSetChanged();
        fragment.getSearch().setAdapter(autoAdapter);

        if (list.size() <= 0) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_list);
            fragment.setContentShown(true);
        } else {
            fragment.setContentEmpty(false);
            adapter.notifyDataSetChanged();
            fragment.setContentShown(true);
        }

        if (flag == Flag.REPO_REFRESH) {
            SuperToast.create(
                    context,
                    context.getString(R.string.repo_refresh_successful),
                    SuperToast.Duration.VERY_SHORT,
                    Style.getStyle(Style.BLUE)
            ).show();
        }
    } else {
        fragment.setContentEmpty(true);
        fragment.setEmptyText(R.string.repo_empty_error);
        fragment.setContentShown(true);
    }
}
 
Example 11
Source File: RepoTask.java    From Bitocle with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(Boolean result) {
    if (result) {
        RAction action = new RAction(context);
        try {
            action.openDatabase(true);
        } catch (SQLException s) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_error);
            fragment.setContentShown(true);
            return;
        }

        List<Repo> repos = action.listRepos();
        Collections.sort(repos);

        List<Map<String, String>> autoList = new ArrayList<Map<String, String>>();

        list.clear();
        autoList.clear();
        for (Repo r : repos) {
            list.add(
                    new RepoItem(
                            r.getName(),
                            r.getDate(),
                            r.getDescription(),
                            r.getLang(),
                            r.getStar(),
                            r.getFork(),
                            r.getOwner(),
                            r.getGit()
                    )
            );
            Map<String, String> map = new HashMap<String, String>();
            map.put("owner", r.getOwner());
            map.put("name", r.getName());
            autoList.add(map);
        }
        action.closeDatabase();

        SimpleAdapter autoAdapter = new SimpleAdapter(
                context,
                autoList,
                R.layout.auto_item,
                new String[] {"owner", "name"},
                new int[] {R.id.auto_item_owner, R.id.auto_item_name}
        );
        autoAdapter.notifyDataSetChanged();
        fragment.getSearch().setAdapter(autoAdapter);

        if (list.size() <= 0) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_list);
            fragment.setContentShown(true);
        } else {
            fragment.setContentEmpty(false);
            adapter.notifyDataSetChanged();
            fragment.setContentShown(true);
        }

        if (flag == Flag.REPO_REFRESH) {
            SuperToast.create(
                    context,
                    context.getString(R.string.repo_refresh_successful),
                    SuperToast.Duration.VERY_SHORT,
                    Style.getStyle(Style.BLUE)
            ).show();
        }
    } else {
        fragment.setContentEmpty(true);
        fragment.setEmptyText(R.string.repo_empty_error);
        fragment.setContentShown(true);
    }
}
 
Example 12
Source File: JsonRequestFragment.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

	View view = inflater.inflate(R.layout.fr_json_request, container,false);

	carDataList = new ArrayList<Map<String, String>>();

	lvCar = (ListView) view.findViewById(R.id.lv_car);
	adapter = new SimpleAdapter(getActivity(), carDataList, R.layout.fr_json_request_list_item, keys, ids);
	lvCar.setAdapter(adapter);

	// 发起请求

	JsonObjectRequest request = new JsonObjectRequest(StringUtil.preUrl(Constants.DEFAULT_JSON_REQUEST_URL), null,
			new Listener<JSONObject>() {

				@Override
				public void onResponse(JSONObject response) {
					try {
						if (!response.has("result")) {
							return;
						}

						JSONObject result = response.getJSONObject("result");

						if (!result.has("fctlist")) {
							return;
						}

						JSONArray factoryArray = result.getJSONArray("fctlist");

						if (factoryArray.length() == 0) {
							return;
						}

						JSONObject factory = factoryArray.getJSONObject(0);

						if (!factory.has("serieslist")) {
							return;
						}

						JSONArray seriesArray = factory.getJSONArray("serieslist");

						carDataList.clear();

						for (int i = 0; i < seriesArray.length(); i++) {
							JSONObject series = seriesArray.getJSONObject(i);
							Map<String, String> seriesMap = new HashMap<String, String>();

							seriesMap.put("name", series.getString("name"));
							seriesMap.put("level", "级别:"+series.getString("levelname"));
							seriesMap.put("price", "价格:"+series.getString("price"));

							carDataList.add(seriesMap);

						}
						
						adapter.notifyDataSetChanged();

					} catch (Exception e) {
						ToastUtil.showToast(getActivity(), getResources().getString(R.string.request_fail_text));
					}

				}
			}, new ErrorListener() {

				@Override
				public void onErrorResponse(VolleyError arg0) {
					ToastUtil.showToast(getActivity(), getResources().getString(R.string.request_fail_text));
				}
			});
	// 请求加上Tag,用于取消请求
	request.setTag(this);

	VolleyUtil.getQueue(getActivity()).add(request);

	return view;
}