当前位置: 编程技术>移动开发
本页文章导读:
▪手动签字apk 和 zipalign优化 手动签名apk 和 zipalign优化
手动签名命令:
命令行输入 jarsigner -verbose -keystore release.keystore -storepass yourkeysotrepassword -keypass yourkeypassword -signedjar yoursignedapkname apkyouwanttosign yourkeyname
例如:
j.........
▪ OC中的NSString的其余用法 OC中的NSString的其他用法
NSLog(@"大写:%@", [str uppercaseString]);
NSLog(@"小写: %@", [str lowercaseString]);
NSLog(@"首字母大写, 其他字母变小写", [@"aGe", capitalizedString]);
BOOL result = [@"abc" isEqualToString:@"Abc"];.........
▪ 自定义listview,带旋钮,多选框,处理item事件 自定义listview,带按钮,多选框,处理item事件产品中要用到这个效果:listitem中带多选框,用来删除;有按钮,处理相应事件;item的click处理跳转。同事说这个设计操作起来很二,有点反社会.........
[1]手动签字apk 和 zipalign优化
来源: 互联网 发布时间: 2014-02-18
手动签名apk 和 zipalign优化
手动签名命令:
命令行输入 jarsigner -verbose -keystore release.keystore -storepass yourkeysotrepassword -keypass yourkeypassword -signedjar yoursignedapkname apkyouwanttosign yourkeyname
例如:
jarsigner -verbose -keystore release.keystore -storepass 123456 -keypass 123456 -signedjar signed.apk unsigned.apk mykey1
优化apk命令:
zipalign -v 4 source.apk androidres.apk
附上bat:
1、使用之前将,发布keystore 放到bat同级目录,将sdk\tools下的zipalign.exe复制到bat同级目(压缩包里附上了我自己的,应该所有人的都是一样的)
2、修改bat中 release.keystore为自己的keystore名,keystorepassword 换成keystore的密码,keypassword 换成key密码,keyname 换成key的别名。
然后用eclipse导出unsigned apk ,然后将apk拖到bat上即可。
[2] OC中的NSString的其余用法
来源: 互联网 发布时间: 2014-02-18
OC中的NSString的其他用法
NSLog(@"大写:%@", [str uppercaseString]); NSLog(@"小写: %@", [str lowercaseString]); NSLog(@"首字母大写, 其他字母变小写", [@"aGe", capitalizedString]); BOOL result = [@"abc" isEqualToString:@"Abc"]; //返回0, 即为false //比较字符串大小. compare会返回3个值中的其中一个 //1. NSOrderedSame 右边的字符串比左边大 //2. NSOrderedAscending 两个字符串的内容相同 //3. NSOrderedDescending 左边的字符串比右边的大 NSComparisonResult result2 = [@"abc" compare:@"Abc"]; if (result2 == NSOrderedSame){ NSLog(@"两个字符串内容相同"); }else if (result2 == NSOrderedAscending){ NSLog(@"右边 > 左边"); }else if (result2 == NSOrderedDescending){ NSLog(@"右边 < 左边"); } //字符串搜索 NSString *str = @"12345.txt"; //是否以12开头 NSLog(@"是否12开头:%i", [str hasPrefix:@12]); //返回1,即true NSLog(@"是否txt结尾:%i", [str hasSuffix:@"txt"]); //返回1,即true //查找是否包含345字符串, 如果没找到,返回的location=NSNotFound //一旦找到字符串就返回,不理会后续是否还有相同的字符串 NSRange range = [str rangeOfString:@"345"]; NSLog(@"%@", NSStringFromRange(range)); if(range.location == NSNotFound){ NSLog(@"不能找到"); } NSRange range = [str rangeOfString:@"345" options: NSBackwardSearch]; //字符串的截取, 从第4位开始截取字符串 NSLog(@"%@", [str substringFromIndex: 3]); NSLog(@"%@", [str substringToIndex: 3]); //截取字符串中间范围, 截取从第3位开始,取3个字符 NSRange range = NSMakeRange(3, 3); NSLog(@"%@", [str substringWithRange: range]); //切割字符串,java中的split NSString *str = @"1,2,3,4,5,6,7"; NSArray *array = [str componentsSeparedByString:@","]; NSLog(@"%@", array); //拿到array第0个位置的字符串, array: [1,2,3,4,5,6,7] NSString *str3 = [array objectAtIndex:0]; //输出1 //文件路径拼接方法 NSMutableArray *components = [NSMutableArray array]; [components addObject: @"User"]; [components addObject: @"MJ"]; [components addObject: @"Desktop"]; NSString *path = [NSString pathWithComponents:components]; NSLog(@"%@", path); //输出User/MJ/Desktop //切割成数组 NSArray *cmps = [path pathComponents]; NSLog(@"%@", cmps); //判断是否是绝对路径 NSString path = @"users/mj/test"; NSLog(@"%i", [path isAbsolutePath]); //输出0,为false //最后一个目录输出 NSLog(@"%@", [path lastPathComponent]); //删除最后一个目录 NSLog(@"%@", [path stringByDeletingLastPathComponent]); //再最后拼接一个目录 NSLog(@"%@", [path stringByAppendingPathComponent:@"abc"]); //输出 users/mj/test/abc //拓展名处理, 获取拓展名 NSString *str = @"/user/desktop/test.text"; NSLog(@"%@", [str pathExtension]); //输出text //删除拓展名方法: stringByDeletingPathExtension //拼接拓展名方法: stringByAppendingPathExtension //强转类型 NSString *val = @"1"; int valint = [val intValue]; //计算数字,不是字符数 NString *value = @"我是字符串"; NSLog("%@", [value length]); //输出5 //取得字符串其中某个字符 NSLog("%@", [value characterAtIndex: 0]); //输出 "我" //转成C语言中的字符串 char *s = [@"abc" UTF8String];
[3] 自定义listview,带旋钮,多选框,处理item事件
来源: 互联网 发布时间: 2014-02-18
自定义listview,带按钮,多选框,处理item事件
ItemInfo.java,一个传递数据的实体类:
布局文件:
3、这里用到了一个下拉刷新的第三方库 com.handmark.pulltorefresh.library,这个在github上有的:
产品中要用到这个效果:listitem中带多选框,用来删除;有按钮,处理相应事件;item的click处理跳转。同事说这个设计操作起来很二,有点反社会,再加个图片和可以展开就反人类了。不管怎样,产品说了,我们就得做。
思路:item上有控件,就不能使item失去焦点,因此,各种button,checkbox就不能去获取焦点,但是可以click。其实主要就这些,其他也没多少东西。
1、首先贴个效果图,全选/取消全选,删除,item的单击,checkbox的单击,button的单击:
2、代码部分:
MainActivity.java
package com.ttdevs.lcb; import java.util.LinkedList; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.CheckBox; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; import com.handmark.pulltorefresh.library.PullToRefreshListView; import com.ttdevs.lcb.CustomAdapter.ViewHolder; public class MainActivity extends Activity implements OnClickListener, OnItemClickListener, OnRefreshListener2<ListView> { private LinkedList<ItemInfo> list; private CustomAdapter adapter; private PullToRefreshListView mPullRefreshListView; private ListView actualListView; private CheckBox cbSelectAll ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cbSelectAll = (CheckBox) findViewById(R.id.cbSelectAll); mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list); mPullRefreshListView.setMode(Mode.BOTH); mPullRefreshListView.setOnRefreshListener(this); actualListView = mPullRefreshListView.getRefreshableView(); // Need to use the Actual ListView when registering for Context Menu registerForContextMenu(actualListView); list = new LinkedList<ItemInfo>(); adapter = new CustomAdapter(getApplicationContext(), list); initData(list); actualListView.setAdapter(adapter); actualListView.setOnItemClickListener(this); } private void initData(LinkedList<ItemInfo> list) { for (int i = 0; i <= 20; i++) { ItemInfo info = new ItemInfo(); info.setId(i); info.setContent("这是第 " + i + " 条记录"); list.add(info); adapter.getSelect().add(false); info = null; } } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ViewHolder holder = adapter.new ViewHolder(); holder.tvItemID = (TextView) view.findViewById(R.id.tvItemID); holder.tvContent = (TextView) view.findViewById(R.id.tvContent); // holder.cbSelect = (CheckBox) view.findViewById(R.id.cbSelect); // holder.btClick = (Button) view.findViewById(R.id.btClick); ItemInfo itemInfo = list.get(position); itemInfo.setId(Integer.parseInt(holder.tvItemID.getText().toString())); itemInfo.setContent(holder.tvContent.getText().toString()); Intent intent = new Intent(this, InfoActivity.class); intent.putExtra("itemInfo", itemInfo); startActivity(intent); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.btDelete: for (int i = 0; i < adapter.getSelect().size(); ) { System.out.println(i+"|" + adapter.getSelect().get(i)); if(adapter.getSelect().get(i)){ adapter.getSelect().remove(i); list.remove(i); } else { i++; } } adapter.notifyDataSetChanged(); cbSelectAll.setChecked(false); break; case R.id.cbSelectAll: boolean flag = cbSelectAll.isChecked(); for (int i = 0; i < adapter.getSelect().size(); i++) { adapter.getSelect().set(i, flag); } adapter.notifyDataSetChanged(); break; default: break; } } @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { Toast.makeText(getApplicationContext(), "下拉刷新", Toast.LENGTH_LONG).show(); new GetLastTask().execute(); } @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { Toast.makeText(getApplicationContext(), "上拉获取更多", Toast.LENGTH_LONG).show(); new GetFirstTask().execute(); } private class GetFirstTask extends AsyncTask<Void, Void, ItemInfo> { @Override protected ItemInfo doInBackground(Void... params) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } ItemInfo info = new ItemInfo(); info.setId((int) (System.currentTimeMillis() % 1000000)); info.setContent("last:" + String.valueOf(System.currentTimeMillis())); return info; } @Override protected void onPostExecute(ItemInfo result) { list.addLast(result); adapter.getSelect().addLast(false); adapter.notifyDataSetChanged(); // TODO 二选一? mPullRefreshListView.onRefreshComplete(); super.onPostExecute(result); } } private class GetLastTask extends AsyncTask<Void, Void, ItemInfo> { @Override protected ItemInfo doInBackground(Void... params) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } ItemInfo info = new ItemInfo(); info.setId((int) (System.currentTimeMillis() % 1000000)); info.setContent("last:" + String.valueOf(System.currentTimeMillis())); return info; } @Override protected void onPostExecute(ItemInfo result) { list.addFirst(result); adapter.getSelect().addFirst(false); adapter.notifyDataSetChanged(); mPullRefreshListView.onRefreshComplete(); super.onPostExecute(result); } } }CustomAdapter.java,这个是自定义的adapter,实现主要的逻辑:
package com.ttdevs.lcb; import java.util.LinkedList; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; public class CustomAdapter extends BaseAdapter { private final LinkedList<Boolean> selected = new LinkedList<Boolean>(); private Context context; private LayoutInflater inflater; private LinkedList<ItemInfo> list; public CustomAdapter(Context context, LinkedList<ItemInfo> list) { this.context = context; this.inflater = LayoutInflater.from(context); this.list = list; } public LinkedList<Boolean> getSelect() { return selected; } @Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { convertView = inflater.inflate(R.layout.listview_item, null); holder = new ViewHolder(); holder.cbSelect = (CheckBox) convertView.findViewById(R.id.cbSelect); holder.tvContent = (TextView) convertView.findViewById(R.id.tvContent); holder.tvItemID = (TextView) convertView.findViewById(R.id.tvItemID); holder.btClick = (Button) convertView.findViewById(R.id.btClick); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } final ItemInfo itemInfo = list.get(position); holder.tvItemID.setText(String.valueOf(itemInfo.getId())); holder.tvContent.setText(itemInfo.getContent()); holder.cbSelect.setChecked(selected.get(position)); holder.cbSelect.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { System.out.println("selected set position:" + position); selected.set(position, !selected.get(position));// 将CheckBox的选中状况记录下来 for (int i = 0; i < selected.size(); i++) { System.out.println("selected " + i + ":" + selected.get(i)); } // notifyDataSetChanged(); } }); holder.btClick.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String value = String.valueOf(position) + "|" + itemInfo.getId() + "|" + itemInfo.getContent(); Toast.makeText(context, value, Toast.LENGTH_SHORT).show(); } }); return convertView; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } public class ViewHolder { public CheckBox cbSelect; public TextView tvContent; public TextView tvItemID; public Button btClick; } }
ItemInfo.java,一个传递数据的实体类:
package com.ttdevs.lcb; import java.io.Serializable; public class ItemInfo implements Serializable { private static final long serialVersionUID = 6287420905418813028L; private int id; private String content; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } }跳转结果页,看自己的业务了:
package com.ttdevs.lcb; import android.app.Activity; import android.os.Bundle; public class InfoActivity extends Activity { private ItemInfo info; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_info); // intent.putExtra("itemInfo", itemInfo); info = (ItemInfo) getIntent().getExtras().get("itemInfo"); System.out.println(info.getId() + "||" + info.getContent()); } }
布局文件:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/llSelectAll" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:orientation="horizontal" > <CheckBox android:id="@+id/cbSelectAll" android:layout_width="28dp" android:layout_height="28dp" android:onClick="onClick" android:layout_alignParentLeft="true" android:layout_centerVertical="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="8dp" android:layout_toRightOf="@+id/cbSelectAll" android:text="全选" /> <Button android:id="@+id/btDelete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:onClick="onClick" android:text="delete" /> </RelativeLayout> <ImageView android:layout_width="match_parent" android:layout_height="2dp" android:background="@android:color/holo_blue_dark" /> </LinearLayout> <com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/pull_refresh_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/llSelectAll" android:cacheColorHint="#00000000" android:divider="#19000000" android:dividerHeight="4dp" android:fadingEdge="none" android:fastScrollEnabled="false" android:footerDividersEnabled="false" android:headerDividersEnabled="false" android:smoothScrollbar="true" /> </RelativeLayout>listview的item,注意两个属性:clickable和focusable
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:minHeight="30dip" android:paddingLeft="6dp" android:paddingRight="6dp" android:paddingTop="4dp" > <CheckBox android:id="@+id/cbSelect" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:clickable="true" android:focusable="false" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_toLeftOf="@+id/btClick" android:layout_toRightOf="@+id/cbSelect" android:orientation="vertical" > <TextView android:id="@+id/tvContent" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@android:color/black" android:text="content" /> <TextView android:id="@+id/tvItemID" android:textColor="@android:color/black" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="id" /> </LinearLayout> <Button android:id="@+id/btClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:clickable="true" android:focusable="false" android:text="click" /> </RelativeLayout>
3、这里用到了一个下拉刷新的第三方库 com.handmark.pulltorefresh.library,这个在github上有的:
Demo:下载
Pulltorefresh:csdn下载,github下载
先导入pulltorefresh library,然后再运行demo
4、有很多改进的地方,欢迎吐槽
最新技术文章: