当前位置: 编程技术>移动开发
本页文章导读:
▪关于播音接收器中可停留的时间 关于广播接收器中可停留的时间
broadcastreceiver的onReceiver方法运行在主线程中,可停留的时间可能和具体的手机有关。目前测试的手机大概可以停留四、五十秒的时候报ANR异常。当然这是在同.........
▪ listView 与 旋钮共存 listView 与 按钮共存
package com.uumap.adapter;import java.util.HashMap;import java.util.List;import android.app.Activity;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Me.........
▪ 上拉城市 下拉城市
package com.uumap.MapInterface;import android.app.Activity;import android.os.Bundle;import android.os.Message;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.widget.AdapterView;impo.........
[1]关于播音接收器中可停留的时间
来源: 互联网 发布时间: 2014-02-18
关于广播接收器中可停留的时间
broadcastreceiver的onReceiver方法运行在主线程中,可停留的时间可能和具体的手机有关。目前测试的手机大概可以停留四、五十秒的时候报ANR异常。当然这是在同一个.apk中只有一个receiver时测试的数据。具体情况最好测试下。
[2] listView 与 旋钮共存
来源: 互联网 发布时间: 2014-02-18
listView 与 按钮共存
package com.uumap.adapter;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import com.uumap.Entity.PoiInfo;
import com.uumap.MapInterface.FavoriteActivity;
import com.uumap.MapInterface.FindActivity;
import com.uumap.MapInterface.R;
import com.uumap.MapInterface.mapIndex;
import com.uumap.adapter.FavoriteListAdapter.lvButtonListener;
import com.uumap.mapview.Map;
import com.uumap.util.CacheTools;
import com.uumap.util.FileUtil;
import com.uumap.util.StrUtil;
import com.uumap.views.PoiImgView;
public class FindResutlAdapter extends BaseAdapter
{
private List<PoiInfo> itemList;
private Context context;
private LayoutInflater lif;
private ViewHolder holder;
public FindResutlAdapter(Context context, List<PoiInfo> itemList)
{
this.context = context;
this.itemList = itemList;
lif = LayoutInflater.from(context);
}
final class ViewHolder
{
public Button mapBtn;
public TextView tv1;
public TextView tv2;
}
@Override
public int getCount()
{
return itemList.size();
}
@Override
public Object getItem(int position)
{
return itemList.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
holder = new ViewHolder();
convertView = lif.inflate(R.layout.findresult_item, null);
holder.mapBtn=(Button) convertView.findViewById(R.id.mapBtn);
holder.tv1 = (TextView) convertView.findViewById(R.id.poi_name);
holder.tv2 = (TextView) convertView.findViewById(R.id.poi_address);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.tv1.setText(itemList.get(position).getName());
String address = "";
address = itemList.get(position).getAddress();
if (address!=null){
if ("".equals(address.trim()))
{
address = "暂无地址信息";
}
}else{
address = "暂无地址信息";
}
holder.tv2.setText(address);
// holder.mapBtn.setOnClickListener(new lvButtonListener(position));
return convertView;
}
public void getMapPoint(int position) {
mapIndex.jwxy[0] = itemList.get(position).getJwx();
mapIndex.jwxy[1] = itemList.get(position).getJwy();
String title = itemList.get(position).getName();
// Map.locateJwxy[0] = mapIndex.jwxy[0];
// Map.locateJwxy[1] = mapIndex.jwxy[1];
CacheTools.select = "SelectPoiActivity";
Bitmap poiImg = BitmapFactory.decodeResource(Map.curContext.getResources(),
R.drawable.poi);
PoiImgView iv = new PoiImgView(Map.curContext, 0);
iv.setImageBitmap(poiImg);
PoiInfo poi = new PoiInfo();
poi.setIv(iv);
poi.setJwx(mapIndex.jwxy[0]);
poi.setJwy(mapIndex.jwxy[1]);
poi.setName(title);
poi.setResultId(0);
poi.setSelect(false);
Map.tmDiv.rstPoi = poi;
if(Map.poiInfos!=null){
Message message = Message.obtain();
mapIndex.selectPoi.handleMessage(message);
}
}
class lvButtonListener implements OnClickListener {
private int position;
lvButtonListener(int pos) {
position = pos;
}
public void onClick(View v) {
int vid = v.getId();
if (vid == holder.mapBtn.getId()) {
getMapPoint(position);
((FindActivity) context).finish();
}
}
}
}
package com.uumap.adapter;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import com.uumap.Entity.PoiInfo;
import com.uumap.MapInterface.FavoriteActivity;
import com.uumap.MapInterface.FindActivity;
import com.uumap.MapInterface.R;
import com.uumap.MapInterface.mapIndex;
import com.uumap.adapter.FavoriteListAdapter.lvButtonListener;
import com.uumap.mapview.Map;
import com.uumap.util.CacheTools;
import com.uumap.util.FileUtil;
import com.uumap.util.StrUtil;
import com.uumap.views.PoiImgView;
public class FindResutlAdapter extends BaseAdapter
{
private List<PoiInfo> itemList;
private Context context;
private LayoutInflater lif;
private ViewHolder holder;
public FindResutlAdapter(Context context, List<PoiInfo> itemList)
{
this.context = context;
this.itemList = itemList;
lif = LayoutInflater.from(context);
}
final class ViewHolder
{
public Button mapBtn;
public TextView tv1;
public TextView tv2;
}
@Override
public int getCount()
{
return itemList.size();
}
@Override
public Object getItem(int position)
{
return itemList.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
holder = new ViewHolder();
convertView = lif.inflate(R.layout.findresult_item, null);
holder.mapBtn=(Button) convertView.findViewById(R.id.mapBtn);
holder.tv1 = (TextView) convertView.findViewById(R.id.poi_name);
holder.tv2 = (TextView) convertView.findViewById(R.id.poi_address);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.tv1.setText(itemList.get(position).getName());
String address = "";
address = itemList.get(position).getAddress();
if (address!=null){
if ("".equals(address.trim()))
{
address = "暂无地址信息";
}
}else{
address = "暂无地址信息";
}
holder.tv2.setText(address);
// holder.mapBtn.setOnClickListener(new lvButtonListener(position));
return convertView;
}
public void getMapPoint(int position) {
mapIndex.jwxy[0] = itemList.get(position).getJwx();
mapIndex.jwxy[1] = itemList.get(position).getJwy();
String title = itemList.get(position).getName();
// Map.locateJwxy[0] = mapIndex.jwxy[0];
// Map.locateJwxy[1] = mapIndex.jwxy[1];
CacheTools.select = "SelectPoiActivity";
Bitmap poiImg = BitmapFactory.decodeResource(Map.curContext.getResources(),
R.drawable.poi);
PoiImgView iv = new PoiImgView(Map.curContext, 0);
iv.setImageBitmap(poiImg);
PoiInfo poi = new PoiInfo();
poi.setIv(iv);
poi.setJwx(mapIndex.jwxy[0]);
poi.setJwy(mapIndex.jwxy[1]);
poi.setName(title);
poi.setResultId(0);
poi.setSelect(false);
Map.tmDiv.rstPoi = poi;
if(Map.poiInfos!=null){
Message message = Message.obtain();
mapIndex.selectPoi.handleMessage(message);
}
}
class lvButtonListener implements OnClickListener {
private int position;
lvButtonListener(int pos) {
position = pos;
}
public void onClick(View v) {
int vid = v.getId();
if (vid == holder.mapBtn.getId()) {
getMapPoint(position);
((FindActivity) context).finish();
}
}
}
}
[3] 上拉城市
来源: 互联网 发布时间: 2014-02-18
下拉城市
package com.uumap.MapInterface;
import android.app.Activity;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import com.uumap.Entity.Province;
import com.uumap.Entity.city;
import com.uumap.adapter.CityAdapter;
import com.uumap.mapview.Map;
import com.uumap.util.CacheTools;
public class ChangeCityActivity extends Activity
{
ListView cityLv;
Spinner proSpinner;
TextView cityNameTv;
boolean isInit = true;
int proIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.change_city);
cityNameTv = (TextView) findViewById(R.id.cityName);
cityNameTv.setText(getResources().getString(R.string.curr_city)
+ mapIndex.cityName);
isInit = true;
proIndex = this.getIntent().getExtras().getInt("index");
cityLv = (ListView) findViewById(R.id.cityList);
CityAdapter ca = new CityAdapter(this, CacheTools.proList.get(proIndex)
.getCityList());
cityLv.setAdapter(ca);
cityLv.setOnItemClickListener(changeCity);
proSpinner = (Spinner) findViewById(R.id.switch_pro);
ArrayAdapter<String> proAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, this.getProNames());
proAdapter.setDropDownViewResource(R.layout.province_item);
proSpinner.setAdapter(proAdapter);
proSpinner.setSelection(proIndex);
proSpinner.setOnItemSelectedListener(changePro);
Map.tmDiv.removeAllViews();
}
public String[] getProNames()
{
String[] proNames = new String[CacheTools.proList.size()];
for (int i = 0; i < CacheTools.proList.size(); i++)
{
proNames[i] = CacheTools.proList.get(i).getName();
}
return proNames;
}
public String[] getProNames2() {
int order = 0;
String[] proNames = new String[CacheTools.proList.size()];
proNames[0] = "直辖市";
proNames[1] = "广东";
for (int i = 1; i < CacheTools.proList.size(); i++) {
if (CacheTools.proList.get(i).getName().equals("广东")) {
i++;
order = -1;
}
proNames[i + 1 + order] = CacheTools.proList.get(i).getName();
}
return proNames;
}
private OnItemClickListener changeCity = new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long id)
{
city ct = (city) adapter.getAdapter().getItem(position);
cityNameTv.setText(getResources().getString(R.string.curr_city)
+ ct.name);
mapIndex.proIndex = proIndex;
Message msg = Message.obtain();
msg.obj = ct;
finish();
Map.ChangeCityHandler.handleMessage(msg);
}
};
private OnItemSelectedListener changePro = new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> adapter, View view,
int position, long id)
{
if (!isInit)
{
Province pro = CacheTools.proList.get(position);
CityAdapter ca = new CityAdapter(ChangeCityActivity.this, pro
.getCityList());
proIndex = position;
cityLv.setAdapter(ca);
}
else
{
isInit = false;
}
}
public void onNothingSelected(AdapterView<?> parent)
{
}
};
}
package com.uumap.adapter;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.uumap.Entity.city;
import com.uumap.MapInterface.R;
public class CityAdapter extends BaseAdapter
{
private List<city> cityList;
private LayoutInflater lif;
public CityAdapter(Context context, List<city> cityList)
{
this.cityList = cityList;
lif = LayoutInflater.from(context);
}
@Override
public int getCount()
{
return cityList.size();
}
@Override
public Object getItem(int position)
{
return cityList.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
final class ViewHolder
{
public TextView cityTv;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder vh = null;
if (convertView == null)
{
vh = new ViewHolder();
convertView = lif.inflate(R.layout.city_item, null);
vh.cityTv = (TextView) convertView.findViewById(R.id.city_name);
convertView.setTag(vh);
}
else
{
vh = (ViewHolder) convertView.getTag();
}
vh.cityTv.setText(cityList.get(position).name);
return convertView;
}
}
package com.uumap.MapInterface;
import android.app.Activity;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import com.uumap.Entity.Province;
import com.uumap.Entity.city;
import com.uumap.adapter.CityAdapter;
import com.uumap.mapview.Map;
import com.uumap.util.CacheTools;
public class ChangeCityActivity extends Activity
{
ListView cityLv;
Spinner proSpinner;
TextView cityNameTv;
boolean isInit = true;
int proIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.change_city);
cityNameTv = (TextView) findViewById(R.id.cityName);
cityNameTv.setText(getResources().getString(R.string.curr_city)
+ mapIndex.cityName);
isInit = true;
proIndex = this.getIntent().getExtras().getInt("index");
cityLv = (ListView) findViewById(R.id.cityList);
CityAdapter ca = new CityAdapter(this, CacheTools.proList.get(proIndex)
.getCityList());
cityLv.setAdapter(ca);
cityLv.setOnItemClickListener(changeCity);
proSpinner = (Spinner) findViewById(R.id.switch_pro);
ArrayAdapter<String> proAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, this.getProNames());
proAdapter.setDropDownViewResource(R.layout.province_item);
proSpinner.setAdapter(proAdapter);
proSpinner.setSelection(proIndex);
proSpinner.setOnItemSelectedListener(changePro);
Map.tmDiv.removeAllViews();
}
public String[] getProNames()
{
String[] proNames = new String[CacheTools.proList.size()];
for (int i = 0; i < CacheTools.proList.size(); i++)
{
proNames[i] = CacheTools.proList.get(i).getName();
}
return proNames;
}
public String[] getProNames2() {
int order = 0;
String[] proNames = new String[CacheTools.proList.size()];
proNames[0] = "直辖市";
proNames[1] = "广东";
for (int i = 1; i < CacheTools.proList.size(); i++) {
if (CacheTools.proList.get(i).getName().equals("广东")) {
i++;
order = -1;
}
proNames[i + 1 + order] = CacheTools.proList.get(i).getName();
}
return proNames;
}
private OnItemClickListener changeCity = new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long id)
{
city ct = (city) adapter.getAdapter().getItem(position);
cityNameTv.setText(getResources().getString(R.string.curr_city)
+ ct.name);
mapIndex.proIndex = proIndex;
Message msg = Message.obtain();
msg.obj = ct;
finish();
Map.ChangeCityHandler.handleMessage(msg);
}
};
private OnItemSelectedListener changePro = new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> adapter, View view,
int position, long id)
{
if (!isInit)
{
Province pro = CacheTools.proList.get(position);
CityAdapter ca = new CityAdapter(ChangeCityActivity.this, pro
.getCityList());
proIndex = position;
cityLv.setAdapter(ca);
}
else
{
isInit = false;
}
}
public void onNothingSelected(AdapterView<?> parent)
{
}
};
}
package com.uumap.adapter;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.uumap.Entity.city;
import com.uumap.MapInterface.R;
public class CityAdapter extends BaseAdapter
{
private List<city> cityList;
private LayoutInflater lif;
public CityAdapter(Context context, List<city> cityList)
{
this.cityList = cityList;
lif = LayoutInflater.from(context);
}
@Override
public int getCount()
{
return cityList.size();
}
@Override
public Object getItem(int position)
{
return cityList.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
final class ViewHolder
{
public TextView cityTv;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder vh = null;
if (convertView == null)
{
vh = new ViewHolder();
convertView = lif.inflate(R.layout.city_item, null);
vh.cityTv = (TextView) convertView.findViewById(R.id.city_name);
convertView.setTag(vh);
}
else
{
vh = (ViewHolder) convertView.getTag();
}
vh.cityTv.setText(cityList.get(position).name);
return convertView;
}
}
最新技术文章: