当前位置: 编程技术>移动开发
本页文章导读:
▪PhoneGap中HTTP链接自动调用本地浏览器解决方法 PhoneGap中HTTP链接自动调用本地浏览器解决办法
PhoneGap项目中,在html页面中,如果存在譬如:<a href="http://www.baidu.com" >百度</a>的链接,点击此链接时,会自动调用本地浏览器。如果不.........
▪ FileInputStream跟FileOutputStream FileInputStream和FileOutputStream
FileInputStream:FileInputStream 用于顺序访问本地文件,用于读取诸如图像数据之类的原始字节流,从超类InputStream中继承了read,close等方法,对文件进行操作,不支持方法.........
▪ 关于ListView中加入并选取checkbox错位的有关问题 关于ListView中加入并选取checkbox错位的问题
在ListView中的列表项中定义checkbox是一个常见手法,不过如果在listview使用了ViewHolder缓存的话就会遇到一个很恶心的问题,就是列表项错位的问题.........
[1]PhoneGap中HTTP链接自动调用本地浏览器解决方法
来源: 互联网 发布时间: 2014-02-18
PhoneGap中HTTP链接自动调用本地浏览器解决办法
PhoneGap项目中,在html页面中,如果存在譬如:<a href="http://www.baidu.com" >百度</a>的链接,点击此链接时,会自动调用本地浏览器。如果不想其自动调用本地浏览器,而是使用PhoneGap内置方式打开呢,则在Android中的设置如下:
1.找到res/xml/cordova.xml
2.将 <access origin="http://127.0.0.1*"/>改成 <access origin="http://*"/>即可
[2] FileInputStream跟FileOutputStream
来源: 互联网 发布时间: 2014-02-18
FileInputStream和FileOutputStream
FileInputStream:
FileInputStream 用于顺序访问本地文件,用于读取诸如图像数据之类的原始字节流,从超类InputStream中继承了read,close等方法,对文件进行操作,不支持方法和方法.它的两个常用的构造方法是: FileInputStream(String filepath/*文件的全称路径*/); FileInputStream(File fileObj/*描述该文件的File对象*/);
可以用这样的方法构造文件输入流:
(1)FileInputStream f1 = new FileInputStream("test.txt");
(2)File f =new File("test.txt"); FileInputStream f2 = new FileInputStream(f);
FileInputStream重写了抽象类 InputStream的读取数据的方法:
public int read(); //从此输入流中读取一个数据字节
public int read(byte[ ] b);//从此输入流中将最多 b.length 个字节的数据读入一个 byte 数组中
public int read(byte[] b,int off, int len);//从此输入流中将最多 len 个字节的数据读入一个 byte 数组中。
如果读取数据时,输入流结束就返回-1.
FileOutputStream:
FileOutputStream用于向一个文本文件写数据.用于写入诸如图像数据之类的原始字节的流,它从超类OutputStream中继承等方法.它常用的构造方法如下:
FileOutputStream(String filepath/*文件的全称路径*/)
FileOutputStream(File fileobj/*描述该文件的对象*/)
FileOutputStream(String filepath,boolean append/*如果为真,文件以追加方式打开,不覆盖已有文件的内容,如果是假,则覆盖原文件的内容*/)
FileOutputStream(File fileObj,boolean append)
FileOutputStream的创建不依赖文件是否存在.如果filepath表示的文件不存在,FileOutputStream在打开前就创建它.如果文件存在,则打开它,准备写入内容. 如果打开一个只读文件,会引发IOException异常.
FileInputStream:
FileInputStream 用于顺序访问本地文件,用于读取诸如图像数据之类的原始字节流,从超类InputStream中继承了read,close等方法,对文件进行操作,不支持方法和方法.它的两个常用的构造方法是: FileInputStream(String filepath/*文件的全称路径*/); FileInputStream(File fileObj/*描述该文件的File对象*/);
可以用这样的方法构造文件输入流:
(1)FileInputStream f1 = new FileInputStream("test.txt");
(2)File f =new File("test.txt"); FileInputStream f2 = new FileInputStream(f);
FileInputStream重写了抽象类 InputStream的读取数据的方法:
public int read(); //从此输入流中读取一个数据字节
public int read(byte[ ] b);//从此输入流中将最多 b.length 个字节的数据读入一个 byte 数组中
public int read(byte[] b,int off, int len);//从此输入流中将最多 len 个字节的数据读入一个 byte 数组中。
如果读取数据时,输入流结束就返回-1.
FileOutputStream:
FileOutputStream用于向一个文本文件写数据.用于写入诸如图像数据之类的原始字节的流,它从超类OutputStream中继承等方法.它常用的构造方法如下:
FileOutputStream(String filepath/*文件的全称路径*/)
FileOutputStream(File fileobj/*描述该文件的对象*/)
FileOutputStream(String filepath,boolean append/*如果为真,文件以追加方式打开,不覆盖已有文件的内容,如果是假,则覆盖原文件的内容*/)
FileOutputStream(File fileObj,boolean append)
FileOutputStream的创建不依赖文件是否存在.如果filepath表示的文件不存在,FileOutputStream在打开前就创建它.如果文件存在,则打开它,准备写入内容. 如果打开一个只读文件,会引发IOException异常.
[3] 关于ListView中加入并选取checkbox错位的有关问题
来源: 互联网 发布时间: 2014-02-18
关于ListView中加入并选取checkbox错位的问题
在ListView中的列表项中定义checkbox是一个常见手法,不过如果在listview使用了ViewHolder缓存的话就会遇到一个很恶心的问题,就是列表项错位的问题,为此我想到了一个自认为还算简单的解决方法,就是在自定义Adapter时加入checkbox.setTag(position)这样一句代码。这里checkbox为当前列表项的复选框,position为当前列表项位置。然后为checkbox设置点击事件,checkbox.setOnClickLinster(this)。最后在onClick(View v)方法中通过switch(v.getTag()){case 1: .......}方式设置点击事件
我的解决方法:
引入一个ArrayList<Boolean>列表,记录每一项当前的状态,然后在getView()中这样使用:holder.checkBox_3.setChecked(checkPosition_3.get(position));
具体看下面:
我这里一个Item里面有3个CheckBox,所以有三个ArrayList<Boolean>列表。
在ListView中的列表项中定义checkbox是一个常见手法,不过如果在listview使用了ViewHolder缓存的话就会遇到一个很恶心的问题,就是列表项错位的问题,为此我想到了一个自认为还算简单的解决方法,就是在自定义Adapter时加入checkbox.setTag(position)这样一句代码。这里checkbox为当前列表项的复选框,position为当前列表项位置。然后为checkbox设置点击事件,checkbox.setOnClickLinster(this)。最后在onClick(View v)方法中通过switch(v.getTag()){case 1: .......}方式设置点击事件
我的解决方法:
引入一个ArrayList<Boolean>列表,记录每一项当前的状态,然后在getView()中这样使用:holder.checkBox_3.setChecked(checkPosition_3.get(position));
具体看下面:
private List<Boolean> checkPosition_3,checkPosition_1,checkPosition_0;
class ListViewAdapter extends BaseAdapter{
private Context context;
public ListViewAdapter(Context context){
this.context=context;
checkPosition_3 = new ArrayList<Boolean>(ITEMS);
checkPosition_1 = new ArrayList<Boolean>(ITEMS);
checkPosition_0 = new ArrayList<Boolean>(ITEMS);
for(int i=0;i<ITEMS;i++){
checkPosition_3.add(false);
checkPosition_1.add(false);
checkPosition_0.add(false);
}
}
public int getCount() {
// TODO Auto-generated method stub
return model.getItems().size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return model.getItems().get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public boolean isEnabled(int position) {
// TODO Auto-generated method stub
return false;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
if(convertView==null){
holder=new ViewHolder();
convertView=LayoutInflater.from(context).inflate(R.layout.simple_list_item_zc14or9, null);
holder.serial = (TextView)convertView.findViewById(R.id.serial);//序号
holder.SS = (TextView)convertView.findViewById(R.id.SS);//赛事
holder.ZDandKD = (TextView)convertView.findViewById(R.id.ZDandKD);//主队 VS 客队
holder.BSSJ = (TextView)convertView.findViewById(R.id.BSSJ);//比赛时间
holder.checkBox_3 = (CheckBox)convertView.findViewById(R.id.checkBox_3);//
holder.checkBox_1 = (CheckBox)convertView.findViewById(R.id.checkBox_1);//
holder.checkBox_0 = (CheckBox)convertView.findViewById(R.id.checkBox_0);//
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
ZC instance=model.getItems().get(position);
holder.serial.setText(instance.serial);
holder.SS.setText(instance.SS);
holder.ZDandKD.setText(instance.ZD+" VS "+instance.KD);
holder.BSSJ.setText(instance.BSSJ);
//为了解决关于ListView+CheckBox,Item超过一屏时数据错乱
holder.checkBox_3.setId(position);
holder.checkBox_3.setChecked(checkPosition_3.get(position));
holder.checkBox_3.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
int id = buttonView.getId();
checkPosition_3.set(id,isChecked); //赋值
updateTextViewInfo();
}
});
holder.checkBox_1.setId(position);
holder.checkBox_1.setChecked(checkPosition_1.get(position));
holder.checkBox_1.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
int id = buttonView.getId();
checkPosition_1.set(id,isChecked); //赋值
updateTextViewInfo();
}
});
holder.checkBox_0.setId(position);
holder.checkBox_0.setChecked(checkPosition_0.get(position));
holder.checkBox_0.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
int id = buttonView.getId();
checkPosition_0.set(id,isChecked); //赋值
updateTextViewInfo();
}
});
return convertView;
}
class ViewHolder {
TextView serial;//序号
TextView SS;//赛事
TextView ZDandKD;//主队 VS 客队
TextView BSSJ;//比赛时间
CheckBox checkBox_3,checkBox_1,checkBox_0;
}
}
我这里一个Item里面有3个CheckBox,所以有三个ArrayList<Boolean>列表。
最新技术文章: