博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android课程---qq登陆页面(练习)
阅读量:6832 次
发布时间:2019-06-26

本文共 8521 字,大约阅读时间需要 28 分钟。

 

AndroidManifest.xml

Activity1.java

package com.hanqi.test3;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import java.util.Timer;import java.util.TimerTask;public class Activity1 extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_1);//        Intent intent = new Intent(this,Activity3.class);        final Intent localIntent = new Intent(this, Activity3.class);        Timer timer = new Timer();        TimerTask tast = new TimerTask() {            @Override            public void run() {                startActivity(localIntent);            }        };        timer.schedule(tast,4000);    }}

Activity3.java

package com.hanqi.test3;import android.app.Activity;import android.app.AlertDialog;import android.app.ProgressDialog;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;public class Activity3 extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_3);    }   public void onclick1 (View v)   {       new AlertDialog.Builder(this)           .setView(R.layout.loginlayout)           .setNeutralButton("取消", null)           .setPositiveButton("登陆", new DialogInterface.OnClickListener() {               @Override               public void onClick(DialogInterface dialog, int which) {                   AlertDialog al = (AlertDialog) dialog;                   EditText ed_pw = (EditText) al.findViewById(R.id.ed_pw);                   String str = ed_pw.getText().toString();                   if (str.equals("123456")) {                       Intent intent = new Intent(Activity3.this, ActivityLast.class);                       startActivity(intent);                   } else {                       Toast.makeText(Activity3.this, "密码错误,请重新输入", Toast.LENGTH_SHORT).show();                   }               }           })           .setCancelable(false)           .show();   }    public void onclick2(View v)    {        new AlertDialog.Builder(this)            .setView(R.layout.loginlayout2)                .setPositiveButton("提交注册", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                        AlertDialog al = (AlertDialog) dialog;                        TextView nc_qq = (TextView) al.findViewById(R.id.nc_qq);                        Toast.makeText(Activity3.this, "注册成功!", Toast.LENGTH_SHORT).show();                    }                })                .show();    }    public void onclick3(View v)    {        final ProgressDialog pd = new ProgressDialog(this);        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);        pd.setMessage("下载进度");        pd.show();        //创建thread实例  重写run方法  启动多线程        new Thread()        {            @Override            public void run() {                super.run();                for (int i = 0;i<=pd.getMax();i++)                {                    try {                        Thread.sleep(100);                    }catch (Exception e)                    {}                    pd.setProgress(i);                }                pd.dismiss();            }        }.start();    }}

ActivityLast.java

package com.hanqi.test3;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;import java.util.ArrayList;import java.util.List;public class ActivityLast extends AppCompatActivity{    List
lf; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_last); ListView yemian =(ListView)findViewById(R.id.yemian); //准备数据源 lf = new ArrayList
(); lf.add(new Haoyou(R.drawable.qq,"会飞的企鹅","[在线]明天上课!")); lf.add(new Haoyou(R.drawable.qq,"明日依旧","[在线]明天上课!2")); lf.add(new Haoyou(R.drawable.qq, "会飞的企鹅3", "[在线]明天上课!3")); lf.add(new Haoyou(R.drawable.qq, "会飞的企鹅4", "[在线]明天上课!4")); yemian.setAdapter(new MyBaseAdapter()); } class MyBaseAdapter extends BaseAdapter { @Override public int getCount() { return lf.size(); } @Override public Object getItem(int position) { return lf.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { Log.e("TAG", "position = " + position); LayoutInflater layoutInflater = getLayoutInflater(); convertView = layoutInflater.inflate(R.layout.loginlayout3, null); } Haoyou haoyou = lf.get(position); ImageView qq = (ImageView) convertView.findViewById(R.id.tx_qq); TextView tv1 = (TextView) convertView.findViewById(R.id.tv1); TextView tv2 = (TextView) convertView.findViewById(R.id.tv2); qq.setImageResource((int) haoyou.getImage()); tv1.setText(haoyou.getName()); tv2.setText(haoyou.getContent()); return convertView; } }}

Haoyou.java

package com.hanqi.test3;/** * Created by Administrator on 2016/4/9. */public class Haoyou {    private int image;    private String name;    private String content;    public Haoyou(int image, String name, String content) {        this.image = image;        this.name = name;        this.content = content;    }    public void setName(String name) {        this.name = name;    }    public void setImage(int image) {        this.image = image;    }    public void setContent(String content) {        this.content = content;    }    public int getImage() {        return image;    }    public String getName() {        return name;    }    public String getContent() {        return content;    }    @Override    public String toString() {        return "Haoyou{" +                "image=" + image +                ", name='" + name + '\'' +                ", content='" + content + '\'' +                '}';    }}

MainActivity.java

package com.hanqi.test3;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }    public void onclick(View v)         {             Intent intent = new Intent(this,Activity1.class);             startActivity(intent);         }    }

 activity_main.xml

activity_3.xml

activity_1.xml

activity_last.xml

loginlayout.xml

loginlayout2.xml

loginlayout.xml

效果图如下:

 

转载于:https://www.cnblogs.com/0927wyj/p/5371610.html

你可能感兴趣的文章
励志写一篇有味道的博文------json
查看>>
oracle赋权
查看>>
c异或加密与解密
查看>>
【转载】ESFramework 平台下可复用的Tcp通信层实现
查看>>
python lib
查看>>
分布式学习资料-专著列表
查看>>
9.配置postfix空客户端
查看>>
计数排序详解以及java实现
查看>>
HTML5介绍
查看>>
图片的title属性和alt属性的区别
查看>>
iOS社会化分享(干货)
查看>>
第八章实验报告
查看>>
使用 gzexe 快速加密解密文件内容
查看>>
java jvm学习笔记十(策略和保护域)
查看>>
Linux(CentOS)挂载移动硬盘
查看>>
JaveWeb 公司项目(7)----- 通过JS动态生成DIV
查看>>
python_控制台输出带颜色的文字方法
查看>>
TiDB 深度实践之旅--真实“踩坑”经历
查看>>
通过Cloudera Manager安装CDH 5.6
查看>>
Android通过JNI实现与C语言的串口通讯操作蓝牙硬件模块
查看>>