安卓自己遇到过的问题

随笔,大家想看就看,不想看可以离开,不欢迎看了骂人的。

1、 子线程传参数传错误,刚开始没有考虑到。

2、 刚开始没有审好题,多走了一大步弯路,多建了一个数据库。

3、 获取spinner的值出现问题getselectitem

4、 Sql语句:"SELECT * FROM intent WHERE Empno='"+id+"'"  UPDATE intent SET dddd=? WHEREeee=?   INTERT INTO intent(dd,dd,dd,dd)VALUES(????)

5、 获取验证码,把验证码点击获取在线程中获取到传到handler中,再用if语句判定跳转。

6、 要多写就多写几个表,多写几个服务,别懒,别想,按着步骤做。

7、 有时间再多写个记住密码。

8、 分层的时候一定要分好。

9、 写登录接口的时候直接把判断是否冻结写上。写注册的时候直接把验证码发过去。

10、           在一个activity里的几个不同按钮点击进入另一个activity里的不同viewpager页面。通过intent发送过去。SetExary,在那边接收到,setItem什么的。

11、           数据库写错了。



编程题

 

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://192.168.14.198:8080/web/a.jpg"));
startActivity(intent);

intent设置动作;

 

控制Toast显示只显示一次

public static Toast toast;
public static void
showToast(Context context,Stringcontent){
   
if (toast==null){
       
toast =Toast.makeText(context,content,Toast.LENGTH_SHORT);
   
}else{
       
toast.setText(content);
   
}
   
toast.show();
}

 

 

控制按钮多长时间不能摁

public static long last;
public static boolean
isClick(){
   
long time= System.currentTimeMillis();
        if
(time-last<1000){
           
return true;
       
}
       
last =time;
    return false;
}

 

 

欢迎界面停留几秒

timer = new Timer();
task = new TimerTask() {
    @Override
    public void run() {
        b--;
        int c = 0;
        if (b==c){
            Intent intent = newIntent(MainActivity.this,Main2Activity.class);
            startActivity(intent);
        }
    }
};
timer.schedule(task,1000,1000);

 

 

 

正则表达式。只能输入邮箱

String ss = “^[0-9a-zA-Z]+\\@ [0-9a-zA-Z]+\\.[0-9a-zA-Z]+$”;

If(!ss.matchs(ss)){

    One.setText(“你二大爷”);

}

 

网络连接POST传参

String data="name=" +  name  + "&age=" + age;

               

       OutputStream       outputStream= connection.getOutputStream();

                     outputStream.write(data.getBytes());

计时器

if (timer==null){
   
timer = new Timer();
   
timerTask = new TimerTask() {
       
@Override
       
public void run() {
           
i--;
           
Message message = new Message();
           
message.obj= i;
           
message.what=200;
           
handler.sendMessage(message);

       
}
    }
;
   
timer.schedule(timerTask, 1000, 1000);//1000ms执行一次
}

 

sharedPreferences记住账号密码

sharedPreferences=getSharedPreferences("xx",MODE_PRIVATE);
String name=   sharedPreferences.getString("name","");
if
(name!=null &&name!="")
{
   
one.setText(sharedPreferences.getString("name",""));
   
two.setText(sharedPreferences.getString("pwd",""));
   
check.setChecked(true);
}
else
   
check.setChecked(false);


check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
   
@Override
   
public void onCheckedChanged(CompoundButtonbuttonView, boolean isChecked) {
        SharedPreferences.Editor editor =getSharedPreferences(
"xx",MODE_PRIVATE).edit();
        if
(check.isChecked()){
            editor.putString(
"name",one.getText().toString());
           
editor.putString("pwd",two.getText().toString());
           
editor.commit();
       
}else{
            editor.remove(
"name");
           
editor.remove("pwd");
       
}
    }
})
;

 

 

欢迎界面只显示一次

 


SharedPreferences sharedPreferences = getSharedPreferences(
"sss", MODE_PRIVATE);
int
xx = sharedPreferences.getInt("key", 0);
if
(xx == 0)

{
    SharedPreferences.Editor editor =sharedPreferences.edit()
;
   
editor.putInt("key", 1);
   
editor.commit();

 

切换中英文

sta.equals("zh")){
    Locale.setDefault(Locale.
ENGLISH);
   
Configuration configuration = getBaseContext().getResources().getConfiguration();
   
configuration.locale = Locale.ENGLISH;
   
getBaseContext().getResources().updateConfiguration(configuration,getBaseContext().getResources().getDisplayMetrics());
   
recreate();

 

Baseadpter

VieHolder vieholder;
    if
(convertView==null){
        vieholder =
new VieHolder();
       
LayoutInflater flater = LayoutInflater.from(context);
       
convertView = flater.inflate(R.layout.main4a,null);
       
vieholder.bianhao= (TextView) convertView.findViewById(R.id.bianhao);
       
vieholder.xingming= (TextView)convertView.findViewById(R.id.xingming);
       
vieholder.keshi= (TextView)convertView.findViewById(R.id.keshi);
       
vieholder.zhicheng= (TextView)convertView.findViewById(R.id.zhicheng);
       
convertView.setTag(vieholder);
   
}else
      
vieholder= (VieHolder) convertView.getTag();
   
Yi yi = list.get(position);
   
vieholder.bianhao.setText(yi.getId()+"");
   
vieholder.xingming.setText(yi.getName()+"");
   
vieholder.keshi.setText(yi.getTitle()+"");
   
vieholder.zhicheng.setText(yi.getDept()+"");
    return
convertView;
}

public class VieHolder{
   
private TextViewbianhao, xingming, keshi, zhicheng;
}

 

3.  折线题(重点)柱状图。饼状图

IP地址

6.7 阈值

 

获取网络那个

 

 

4.  升序降序 (差不多)

Collections.sort(lst, new CarCompareMore());
if
(!sortFlag)
    Collections.reverse(
lst);

 

6.7 阈值

10. 排序

11. 没有头绪

 

适配器。

 

左滑菜单。

 

Ip

 

DialogEdittext获取值)

final View layout = View.inflate(context, R.layout.password, null);

final
AlertDialog.Builderbuilder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("安全支付");
builder.setMessage("支付密码:");
builder.setView(layout);
builder.setNegativeButton("确定",new DialogInterface.OnClickListener() {
   
@Override
   
public void onClick(DialogInterfacedialog, int which) {
       
/*edit10 = (EditText)builder.findViewById(R.id.edit10);*/
       
edit10 =(EditText) layout.findViewById(R.id.edit10);
       
String zhu = edit10.getText().toString();
      
// int jag = Integer.valueOf(zhu);
       
if (zhu.equals("123456")){
            Toast.makeText(
context, "密码输入正确", Toast.LENGTH_SHORT).show();
           
String uri="http://192.168.14.196:8080/MyWeb/SetCarAccountRechargeServlet";
            new
MyThread2(uri,  edit.getText().toString(),  edit2.getText().toString(), context, handler ).start();
       
}else{
            Toast.makeText(
context, "密码输入错误,请重新输入", Toast.LENGTH_SHORT).show();
       
}
    }
})
;
builder.show();

 

自动手动控制

 

比较值的大小 equals

 

比较时间

public class CarCompareMore implements Comparator<CarAccountRecharge>{

SimpleDateFormatsdf =   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   
Calendar calendar=Calendar.getInstance();
   
Calendar calendar1=Calendar.getInstance();
    try
{
        calendar.setTime(sdf.parse(o1.getDate()) )
;
       
calendar1.setTime( sdf.parse(o2.getDate()) );
   
} catch(ParseException e) {
        e.printStackTrace()
;
   
}

   
if(  calendar.compareTo(calendar1)>0)
       
return  1;
    else
        return 
0;
}

 

 

服务器

 

防误触

Private long startTime = 0

@Override
public void onBackPressed() {
   
long currentTime= System.currentTimeMillis();
    if
(currentTime - startTime >=3000){
        Toast.makeText(
context,"再按一次退出",Toast.LENGTH_SHORT).show();
       
startTime =currentTime;
   
}else{
        finish()
;
   
}

 

 

 

 

获取当前时间

SimpleDateFormat sf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date currdate = new Date(System.currentTimeMillis());
String str = sf.format(currdate);

 

 

慢慢显示

Animation animation= AnimationUtils.loadAnimation(context,R.anim.list_anim);
LayoutAnimationController con = new LayoutAnimationController(animation);
con.setDelay(0.5f);
con.setOrder(LayoutAnimationController.ORDER_NORMAL);
listView.setLayoutAnimation(con);

 

 

 

半透明

AlertDialog dialog= builder.show();
Window window = dialog.getWindow();
WindowManager.LayoutParams layoutParams= window.getAttributes();
layoutParams.alpha = 0.5f;
window.setAttributes(layoutParams);

 

 

Edittext只显示一行

android:singleLine="false"

 

SimpleAdaper BaseAdaper

猜你喜欢

转载自blog.csdn.net/haojiagou/article/details/78894241