- 博客(16)
- 收藏
- 关注
原创 线程和Synchronized的突发奇想
昨天写完售票系统,后面突然有个想法迸出来,如果线程数大于售票数会怎样?于是写了个代码测试了一下。public class TicketWindow implements Runnable { public int totalTickets; public int i = 0; public void setTotalTickets(int totalTickets) ...
2019-11-15 22:00:36
141
原创 售票系统
设计一个简单的卖票模型,就是有个卖票系统,设定好窗口数和总票数,开始卖票,各个窗口共享总票数,卖完为止。下面是代码:public class SellTicketSystem{ private int totalTickets; private int i; public void setTotalTickets(int totalTickets) { ...
2019-11-13 16:57:01
2806
原创 synchronized测试
public class BeSynchronized { private BeSynchronized() { } public static BeSynchronized getInstance() { return getIns.INSTANCE.returnInstance(); } public void runBeS...
2019-11-12 16:49:10
332
原创 enum(枚举)实现单例模式
public class SingleModel { private int a,b; public int getA() { return a; } public void setA(int a) { this.a = a; } public int getB() { return b; ...
2019-11-12 16:13:14
273
原创 Longest Palindromic Substring(最长回文子字符串)
什么是回文?就是正着的字符串和反着的字符串是一样的。比如“aba”,比如“owekkewo”。这个算法在leetcode上判定时间过长,而没通过,先记录一下吧,后面想想怎么改善。 public class Solution { private Object object; public String longestPalindrome(String s) {
2017-02-18 19:38:08
263
原创 Longest Substring Without Repeating Characters(最长无重复子字符串算法)
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le
2017-02-18 00:21:30
291
原创 MotionEvent简析
Class OverviewObject used to report movement (mouse, pen, finger, trackball) events. Motion events may hold either absolute or relative movements and other data, depending on the type of device.用于播报动作
2016-10-06 21:51:05
399
原创 CircleImageView分析
先把代码贴上。为了方便分析,所以有些System.out.println。public class CircleImageView extends ImageView { private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP; private static final Bitmap.Config BITMAP
2016-09-01 22:29:32
275
原创 RecyclerView源码草析
不得不说,看源码使人成长,哈哈哈哈哈。 主要是对onCreateViewHolder这个方法public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);里面的参数parent的来源不熟悉、不知道是什么鬼。于是就去看源码。首先看这个方法的注释 /** * Called when Recyc
2016-08-13 16:28:27
405
原创 自定义一个带删除按钮的ListView
OK,回顾一下ListView的内容。 要把数据通过ListView显示到屏幕,那么就要有三个东西,ListView&Adapter&data。先把全部代码放给大家看吧。 首先是布局文件,分别为Activity.xml布局文件,delete_button.xml布局文件,item_show.xml布局文件。<?xml version="1.0" encoding="utf-8"?><Relat
2016-08-12 23:17:05
2642
原创 简单的removeView和AddView测试
平时我们在Activity类中的onCreate()方法内,加载布局是这么写的。 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main)
2016-08-11 17:18:13
10310
原创 回调函数2
还是实现一个点击按钮public class MainActivity extends Activity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
2016-08-10 20:16:13
222
原创 回调函数
接口: public interface MyInterface { void Result(int result); }实现接口的类: public class Client implements MyInterface {//Service类的引用private Service service;/** * 把传递过来的Caller的类变量赋值给Client中的类
2016-08-10 17:36:33
283
原创 Adapter初步学习
Adapter初步学习public interface Adapter可以看出Adapter是个接口,所以我们如果要使用Adapter,要么继承一个实现了该接口的类,要么实现这个接口。Class OverviewAn Adapter object acts as a bridge between an AdapterView and the underlying d
2016-07-26 00:00:02
259
原创 SimpleAdapter初级使用
public class MainActivity extends Activity { private String[] name = { "张龙", "赵虎", "王朝", "马汉" }; private String[] desc = { "保镖一号", "保镖二号", "保镖三号", "保镖四号" }; private int[] images = {R.dr
2016-07-24 15:11:55
258
原创 SimpleAdapter初步理解
SimpleAdapter初级使用谷歌官方文档:An easy adapter to map static data to views defined in an XML file. You can specify the data backing the list as an ArrayList of Maps. Each entry in the ArrayList correspon
2016-07-23 14:54:54
272
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人