当前位置: 编程技术>移动开发
本页文章导读:
▪兑现由无网络连上网络自动刷新数据 实现由无网络连上网络自动刷新数据
最近做过一个客户端项目,客户要求如果在无网络的情况下打开客户端,在连上网络的同时需要刷新当前打开页面的数据。思考良久,因为我的架构是htt.........
▪ listview分页(上一页,下一页成效)并支持过滤(一) listview分页(上一页,下一页效果)并支持过滤(一)
最近在做一个项目,经理要求查询出来的结果能够分页查看,是上一页 下一页的效果,且带过滤的功能,经过几天的奋斗,又是google又是.........
▪ 科大讯飞开发包开展代码混淆后不可用 科大讯飞开发包进行代码混淆后不可用
使用科大讯飞android开发sdk SpeechApi.jar.打包时,进行代码混淆的话,会导致功能不可用。
需要在proguard-project.txt里面加上两行
-keep class com.iflytek.speech.** .........
[1]兑现由无网络连上网络自动刷新数据
来源: 互联网 发布时间: 2014-02-18
实现由无网络连上网络自动刷新数据
最近做过一个客户端项目,客户要求如果在无网络的情况下打开客户端,在连上网络的同时需要刷新当前打开页面的数据。
思考良久,因为我的架构是http+各种请求基类+各种实现子类,那我可以用 广播+接口+Application+接口实现类实现,这就避免了比较麻烦的情况出现,下面即是全部流程。
广播(ConnectionChangeReceiver)
View Code
/**
* 网络状态改变监听状态 调用刷新方法
* @author YuanShuQiao
*
*/
public class ConnectionChangeReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if(null==MyApplication.activitys||MyApplication.activitys.isFinishing())
return;
if(null==MyApplication.connectionListeners)
return;
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null&&networkInfo.isConnectedOrConnecting())
MyApplication.connectionListeners.restartLoad();
}
}
Application声明当前页面接口类
public static ConnectionListener connectionListeners;
页面刷新接口类
/**
* 网络状态改变调用接口
* @author YuanShuQiao
*
*/
public interface ConnectionListener {
public void restartLoad();
}
请求基类实现页面刷新接口类
public class StLoadableActivity extends Activity implements StTaskListener ,ConnectionListener
重写刷新接口方法
public void restartLoad() {
//代码自理
}
主配置文件声明相关广播
<receiver android:name="xxx.xxx.ConnectionChangeReceiver"
android:label="NetworkConnection">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
相关权限依据个人需求酌情添加
1 楼
ray_linn
5 小时前
。。。。一个dos bat 就能实现的事情。
2 楼
ray_linn
5 小时前
@echo off
:enable WLAN
netsh interface set interface name="我的连接" admin=ENBALED
:getip
ipconfig /renew 我的连接
:browser
start http://www.sina.com.cn
连这么简单的dos batch都搞不定,基本功太差
:enable WLAN
netsh interface set interface name="我的连接" admin=ENBALED
:getip
ipconfig /renew 我的连接
:browser
start http://www.sina.com.cn
连这么简单的dos batch都搞不定,基本功太差
[2] listview分页(上一页,下一页成效)并支持过滤(一)
来源: 互联网 发布时间: 2014-02-18
listview分页(上一页,下一页效果)并支持过滤(一)
最近在做一个项目,经理要求查询出来的结果能够分页查看,是上一页 下一页的效果,且带过滤的功能,经过几天的奋斗,又是google又是百度,终于研究出来了,现在总结一下。
先上图,看下效果
先说一下分页,google “Android分页”,大部分都是滚动加载,而有上一页下一页效果的,网上很多都是同一个例子,就是data是一个String型的数组,在其最重要的getView()方法中,写得很让人看不懂,自己又参考了其它的例子,终于明白了,于是就有了以下的代码:
DsznzActivity代码:
public class DsznzActivity extends Activity {
private ArrayList<HashMap<String, String>> listItem;
private ListView list_ylfn;
Button btnPre, btnNext;
View.OnClickListener clickListener;
// 用于显示每列5个Item项。
int VIEW_COUNT = 10;
// 用于显示页号的索引
int index = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_ylfn);
list_ylfn = (ListView) findViewById(R.id.listYlfn);
btnPre = (Button) findViewById(R.id.btnPre);
btnNext = (Button) findViewById(R.id.btnNext);
listItem = new ArrayList<HashMap<String, String>>();
HttpClient client = new DefaultHttpClient();
HttpEntity entity = null;
try {
String uri = GetConnParams.getConnUri()
+ "/phone_listYlfn?zgy.zgynum=" + zgynumLoged;
//此处是从服务端获取数据,有些代码就省略了
HttpPost request = new HttpPost(uri);
HttpResponse response;
response = client.execute(request);
if (response.getStatusLine().getStatusCode() == 200) {
entity = response.getEntity();
}
String json = EntityUtils.toString(entity, "UTF-8").trim();
JSONArray array = new JSONArray(URLDecoder.decode(json, "utf-8"));
for (int i = 0; i < array.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("ylfn_did", array.getJSONObject(i).getString("did"));
map.put("ylfn_name", array.getJSONObject(i).getString("name"));
map.put("gmsfz", array.getJSONObject(i).getString("gmsfz"));
listItem.add(map);
tmpListItem.add(map);
}
// // 生成适配器的Item和动态数组对应的元素
// SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,// 数据源
// R.layout.ylfn,// ListItem的XML实现
// // 动态数组与ImageItem对应的子项
// new String[] { "ylfn_did", "ylfn_name", "gmsfz" },
// // ImageItem的XML文件里面的一个ImageView,两个TextView ID
// new int[] { R.id.ylfn_did, R.id.ylfn_name, R.id.gmsfz });
//
myAdapter=new MyAdapter(this);
list_ylfn.setAdapter(myAdapter);
clickListener = new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btnPre:
preView();
break;
case R.id.btnNext:
nextView();
break;
}
}
};
// 添加2个Button的监听事件。
btnPre.setOnClickListener(clickListener);
btnNext.setOnClickListener(clickListener);
// 检查2个Button是否是可用的
checkButton();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(entity!=null)
entity.consumeContent();
client.getConnectionManager().shutdown();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// 点击左边的Button,表示向前翻页,索引值要减1.
public void preView() {
index--;
// 刷新ListView里面的数值。
myAdapter.notifyDataSetChanged();
// 检查Button是否可用。
checkButton();
}
// 点击右边的Button,表示向后翻页,索引值要加1.
public void nextView() {
index++;
// 刷新ListView里面的数值。
myAdapter.notifyDataSetChanged();
// 检查Button是否可用。
checkButton();
}
public void checkButton() {
// 索引值小于等于0,表示不能向前翻页了,以经到了第一页了。
// 将向前翻页的按钮设为不可用。
if (index <= 0) {
btnPre.setEnabled(false);
}else{
btnPre.setEnabled(true);
}
// 值的长度减去前几页的长度,剩下的就是这一页的长度,如果这一页的长度比View_Count小,表示这是最后的一页了,后面在没有了。
// 将向后翻页的按钮设为不可用。
if (listItem.size() - index * VIEW_COUNT <= VIEW_COUNT) {
btnNext.setEnabled(false);
}
// 否则将2个按钮都设为可用的。
else {
btnNext.setEnabled(true);
}
}
// ListView的Adapter,这个是关键的导致可以分页的根本原因。
public class MyAdapter extends BaseAdapter {
Activity activity;
public MyAdapter(Activity a) {
activity = a;
}
// 设置每一页的长度,默认的是View_Count的值。
@Override
public int getCount() {
// TODO Auto-generated method stub
// return data.length;
// ori表示到目前为止的前几页的总共的个数。
int ori = VIEW_COUNT * index;
// 值的总个数-前几页的个数就是这一页要显示的个数,如果比默认的值小,说明这是最后一页,只需显示这么多就可以了
if (listItem.size() - ori < VIEW_COUNT) {
return listItem.size() - ori;
}
// 如果比默认的值还要大,说明一页显示不完,还要用换一页显示,这一页用默认的值显示满就可以了。
else {
return VIEW_COUNT;
}
}
@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;
}
//重点是getView方法
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// return addTestView(position);
convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.ylfn,null);
TextView ylfn_did_view = (TextView)convertView.findViewById(R.id.ylfn_did);
TextView ylfn_name_view = (TextView)convertView.findViewById(R.id.ylfn_name);
TextView ylfn_gmsfz_view = (TextView)convertView.findViewById(R.id.gmsfz);
ylfn_did_view.setText(listItem.get(position + index * VIEW_COUNT).get("ylfn_did"));
ylfn_name_view.setText(listItem.get(position + index * VIEW_COUNT).get("ylfn_name"));
ylfn_gmsfz_view.setText(listItem.get(position + index * VIEW_COUNT).get("gmsfz"));
return convertView;
}
}
}
list_ylfn.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/beijing">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="36dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginTop="44dip">
<TextView
android:layout_width="40dp"
android:layout_height="36dp"
android:gravity="center"
android:text="编号"
android:textSize="12sp" />
<TextView
android:layout_width="160dp"
android:layout_height="36dp"
android:gravity="center"
android:text="姓名"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="36dp"
android:gravity="center"
android:text="身份证号"
android:textSize="12sp" />
</LinearLayout>
<ListView android:id="@+id/listYlfn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="88dp"
android:layout_marginBottom="32dip"
android:textFilterEnabled="true">
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="32dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/btnPre"
android:layout_width="80dip"
android:layout_height="32dip"
android:text="上一页"
android:textSize="12sp" />
<Button
android:id="@+id/btnNext"
android:layout_width="80dip"
android:layout_height="32dip"
android:layout_marginLeft="20dip"
android:text="下一页"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
ylfn.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView android:text="编号"
android:layout_width="40dp"
android:layout_height="36dp"
android:id="@+id/ylfn_did"
android:gravity="center"
android:textSize="12sp"
android:textColor="#000000"/>
<TextView android:text="姓名"
android:layout_width="80dp"
android:layout_height="36dp"
android:id="@+id/ylfn_name"
android:gravity="center"
android:textSize="12sp"
android:textColor="#000000"/>
<TextView android:text="身份证号"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:id="@+id/gmsfz"
android:gravity="center"
android:textSize="12sp"
android:textColor="#000000"/>
</LinearLayout>
[3] 科大讯飞开发包开展代码混淆后不可用
来源: 互联网 发布时间: 2014-02-18
科大讯飞开发包进行代码混淆后不可用
使用科大讯飞android开发sdk SpeechApi.jar.打包时,进行代码混淆的话,会导致功能不可用。
需要在proguard-project.txt里面加上两行
-keep class com.iflytek.speech.** {*;}
-keepattributes Signature
最新技术文章: