微博通

做一个Android端的微博项目

每个控件都要实现功能。例如:申请账号按钮被点击后转到一个新的Activity,进行帐号申请的工作。

登录按钮被点击后转到微博界面(一个新的Activity),在TextView里显示以前发布的微博内容和时间(可以设置多个TextView),并有按钮“发布新微博”和“返回”。

发布新微博按钮被点击后转到一个新的Activity,该页面有一个TextView、一个EditText,一个“提交”按钮。TextView提示EditText剩余的字符数,超出限制后进行提醒,EditText的最大字符数是300。点击提交按钮后转到微博界面。

微博通登录界面:

 

import android.R.bool;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
	EditText edtid,edtpassword;
	Button btnreg,btnlog;
	int num=0;
	User user[]=new User[100];
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		edtid=(EditText)findViewById(R.id.edtid);
		edtpassword=(EditText)findViewById(R.id.edtpassword);
		btnreg=(Button)findViewById(R.id.btnreg);
		btnlog=(Button)findViewById(R.id.btnlog);
		btnreg.setOnClickListener(new MyfristButton());
		btnlog.setOnClickListener(new MysecondButton());
		Intent intent=new Intent();
		String struser=intent.getStringExtra("user");
		String strid=intent.getStringExtra("id");
		String strpassword=intent.getStringExtra("password");
		String strmailbox=intent.getStringExtra("mailbox");
		user[num]=new User();
		user[num].name=struser;
		user[num].id=strid;
		user[num].password=strpassword;
		user[num++].mailbox=strmailbox;
	}
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	class MyfristButton implements OnClickListener{//申请注册
		public void onClick(View arg0){
			Intent intent=new Intent(MainActivity.this,Register.class);
			startActivity(intent);
		}
	}
	class MysecondButton implements OnClickListener{//登录
		public void onClick(View arg0){
			boolean ok=false;
			String logid=edtid.getText().toString();
			String logpassword=edtpassword.getText().toString();
			for(int i=0;i<num;i++){
				if(logid.equals(user[i].id)&&logpassword.equals(user[i].password)){
					ok=true;
				}
			}Intent intent=new Intent(MainActivity.this,Main_Interface.class);
				startActivity(intent);
		}
	}

}

 

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" 
    android:background="@drawable/background3"
    >
   <!--  加载图片 -->
	<ImageView
	    android:id="@+id/image"
	    android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/weibotong"
	    />
    <EditText
        android:id="@+id/edtid"
        android:layout_width="160px"
        android:layout_height="wrap_content"
        android:layout_below="@id/image"
		android:layout_marginTop="10px"
		android:layout_centerHorizontal="true"
		android:background="@drawable/shape"
        android:hint="请输入微博账号"
        />
   	<TextView
   	    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/edtid"
        android:layout_alignTop="@id/edtid"
        android:gravity="left"
        android:text="账号"
   	    />
    <EditText
        android:id="@+id/edtpassword"
        android:layout_width="160px"
        android:layout_height="wrap_content"
        android:layout_below="@id/edtid"
        android:layout_marginTop="10px"
        android:layout_centerHorizontal="true"
		android:background="@drawable/shape"
		android:inputType="textPassword"
		android:maxLength="20"
        />
    <TextView
   	    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/edtpassword"
        android:layout_alignTop="@id/edtpassword"
        android:gravity="left"
        android:text="密码"
   	    />
    <Button
        android:id="@+id/btnreg"
        android:layout_width="80px"
        android:layout_height="wrap_content"
        android:layout_below="@id/edtpassword"
        android:layout_alignLeft="@id/edtpassword"
        android:layout_marginTop="20px"
        android:background="@color/powderblue"
        android:text="申请注册"
        />
    
	 <Button
        android:id="@+id/btnlog"
        android:layout_width="80px"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/btnreg"
        android:layout_alignBaseline="@id/btnreg"
        android:layout_alignBottom="@id/btnreg"
        android:layout_marginLeft="20px"
        android:background="@color/powderblue"
        android:text="登录"
        />
</RelativeLayout>

注册界面:

 

 

 

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Register extends Activity{
	Button btn1,btn2,btn3;
	EditText edtuser,edtid,edtpassword,edtsurepassword,edtmailbox;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.second_activity);
		btn1=(Button)findViewById(R.id.btn1);
		btn2=(Button)findViewById(R.id.btn2);
		btn3=(Button)findViewById(R.id.btn3);
		edtuser=(EditText)findViewById(R.id.edtuser);
		edtid=(EditText)findViewById(R.id.edtid);
		edtpassword=(EditText)findViewById(R.id.edtpassword);
		edtsurepassword=(EditText)findViewById(R.id.edtsurepassword);
		edtmailbox=(EditText)findViewById(R.id.edtmailbox);
		btn1.setOnClickListener(new MyfristButton());
		btn2.setOnClickListener(new MysecondButton());
		btn3.setOnClickListener(new MythirdButton());
	}
	class MyfristButton implements OnClickListener{//提交按钮监听器
		public void onClick(View arg0){
			String struser=edtuser.getText().toString();
			String strid=edtid.getText().toString();
			String strpassword=edtpassword.getText().toString();
			String strmailbox=edtmailbox.getText().toString();
			String strsurepassword=edtsurepassword.getText().toString();
			if(strpassword.equals(strsurepassword)){
				Intent intent=new Intent(Register.this,MainActivity.class);
				intent.putExtra("user", struser);
				intent.putExtra("id", strid);
				intent.putExtra("password", strpassword);
				intent.putExtra("mailbox",strmailbox);
				startActivity(intent);
			}
		}
	}
	class MysecondButton implements OnClickListener{//重置按钮监听器
		public void onClick(View arg0){
			edtuser.setText("");
			edtid.setText("");
			edtpassword.setText("");
			edtsurepassword.setText("");
			edtmailbox.setText("");
		}
	}
	class MythirdButton implements OnClickListener{//返回按钮监听器
		public void onClick(View arg0){
			Intent intent=new Intent(Register.this,MainActivity.class);
			startActivity(intent);
		}
	}
}

布局:

 

 

 

<?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:orientation="vertical"
    android:background="@drawable/background4"
    	>
    <ImageView
	    android:id="@+id/picture1"
	    android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/picture1"
	    />
     <EditText
        android:id="@+id/edtuser"
        android:layout_width="150px"
        android:layout_height="wrap_content"
        android:layout_below="@id/picture1"
		android:layout_marginTop="10px"
		android:layout_centerHorizontal="true"
		android:background="@drawable/shape"
        />
    <TextView
   	    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/edtuser"
        android:layout_alignTop="@id/edtuser"
        android:gravity="left"
        android:text="用户名"
   	    />
    <EditText
        android:id="@+id/edtid"
        android:layout_width="150px"
        android:layout_height="wrap_content"
        android:layout_below="@id/edtuser"
		android:layout_marginTop="10px"
		android:layout_centerHorizontal="true"
		android:background="@drawable/shape"
        />
    <TextView
   	    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/edtid"
        android:layout_alignTop="@id/edtid"
        android:gravity="left"
        android:text="账号"
   	    />
    <EditText
        android:id="@+id/edtpassword"
        android:layout_width="150px"
        android:layout_height="wrap_content"
        android:layout_below="@id/edtid"
        android:layout_marginTop="10px"
        android:layout_centerHorizontal="true"
		android:background="@drawable/shape"
		android:inputType="textPassword"
		android:maxLength="20"
        />
    <TextView
   	    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/edtpassword"
        android:layout_alignTop="@id/edtpassword"
        android:gravity="left"
        android:text="密码"
   	    />
    <EditText
        android:id="@+id/edtsurepassword"
        android:layout_width="150px"
        android:layout_height="wrap_content"
        android:layout_below="@id/edtpassword"
        android:layout_marginTop="10px"
        android:layout_centerHorizontal="true"
		android:background="@drawable/shape"
		android:inputType="textPassword"
		android:maxLength="20"
        />
     <TextView
   	    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/edtsurepassword"
        android:layout_alignTop="@id/edtsurepassword"
        android:gravity="left"
        android:text="确认密码"
   	    />
     <EditText
        android:id="@+id/edtmailbox"
        android:layout_width="150px"
        android:layout_height="wrap_content"
        android:layout_below="@id/edtsurepassword"
        android:layout_marginTop="10px"
        android:layout_centerHorizontal="true"
		android:background="@drawable/shape"
		android:maxLength="20"
        />
     <TextView
   	    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/edtmailbox"
        android:layout_alignTop="@id/edtmailbox"
        android:gravity="left"
        android:text="邮箱"
   	    />
     <Button 
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/edtmailbox"
        android:layout_below="@+id/edtmailbox"
        android:layout_marginTop="20px"
        android:text="提交"
         />
     <Button 
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/btn1"
        android:layout_toRightOf="@+id/btn1"
        android:layout_marginLeft="5px"
        android:text="重置"
         />
     <Button 
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/btn2"
        android:layout_toRightOf="@+id/btn2"
        android:layout_marginLeft="5px"
        android:text="返回"
         />

</RelativeLayout>

微博通主界面:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main_Interface extends Activity{
	Button btn1,btn2;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.third_activity);
		btn1=(Button)findViewById(R.id.btn1);
		btn2=(Button)findViewById(R.id.btn2);
		btn1.setOnClickListener(new MyButton1());
		btn2.setOnClickListener(new MyButton2());
	}
	class MyButton1 implements OnClickListener{//发布新微博
		public void onClick(View arg0){
			Intent intent=new Intent(Main_Interface.this,SendWeibo.class);
			startActivity(intent);
		}
	}
	class MyButton2 implements OnClickListener{//返回
		public void onClick(View arg0){
			Intent intent=new Intent(Main_Interface.this,MainActivity.class);
			startActivity(intent);
		}
	}
}

布局:

 

 

 

<?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:orientation="vertical"
    android:background="@drawable/background2">"
    <TextView
        android:id="@+id/tet1"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_centerHorizontal="true"
    	android:textSize="25px"
    	android:text="欢迎使用微博通"
        />
    <TextView
        android:id="@+id/tet2"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
		android:layout_below="@+id/tet1"
		android:layout_marginTop="20px"
		android:textSize="15px"
    	android:text="I love Android!!  2014年4月20日"
        />
    <TextView
        android:id="@+id/tet3"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
		android:layout_below="@+id/tet2"
		android:layout_marginTop="20px"
		android:layout_alignLeft="@+id/tet2"
		android:textSize="15px"
    	android:text="I love Android very much!!  2014年4月21日"
        />
    <TextView
        android:id="@+id/tet4"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
		android:layout_below="@+id/tet3"
		android:layout_marginTop="20px"
		android:layout_alignLeft="@+id/tet3"
		android:textSize="15px"
    	android:text="I love Android very very much!!  2014年4月22日"
        />
    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
		android:layout_below="@+id/tet4"
		android:layout_marginTop="30px"
		android:layout_alignLeft="@+id/tet4"
		android:text="发布新微博"
        />
    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
		android:layout_below="@+id/tet4"
		android:layout_toRightOf="@+id/btn1"
		android:layout_marginTop="30px"
		android:layout_marginLeft="50px"
		android:layout_centerHorizontal="true"
		android:text="返回"
        />

</RelativeLayout>

发布微博界面:

 

 

 

import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.graphics.YuvImage;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SendWeibo extends Activity{
	Button btn;
	EditText edt;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.forth_activity);
		btn=(Button)findViewById(R.id.btn);
		edt=(EditText)findViewById(R.id.edt);
		final TextView t=(TextView)findViewById(R.id.yu);
		btn.setOnClickListener(new myButton());
		edt.addTextChangedListener(new TextWatcher() {//EditText监听器
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				int count=s.length();
				int num=300-count;
				t.setText("还剩余"+num+"个字");
				
			}
		});
		
	}
	class myButton implements OnClickListener{
		public void onClick(View arg0){
			Intent intent=new Intent(SendWeibo.this,Main_Interface.class);
			startActivity(intent);
		}
	}
}

布局:

 

 

 

<?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:orientation="vertical"
    android:background="@drawable/background1">"
    <EditText
        android:id="@+id/edt"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:background="@drawable/shape"
        />
    <Button 
        android:id="@+id/btn"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_below="@+id/edt"
    	android:layout_alignLeft="@+id/edt"
    	android:layout_marginTop="30px"
    	android:text="发布"
        />
    <TextView
        android:id="@+id/yu"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_toRightOf="@+id/btn"
    	android:layout_below="@+id/edt"
    	android:layout_alignTop="@+id/btn"
    	android:layout_marginLeft="30px"
        />
</RelativeLayout>

 

 

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值