- 1. java
- MainActivity.java
- ArticleListActivity.java
- 2. xml
- login.xml
- activity_main.xml
- activity_article_list.xml
- AndroidManifest.xml
package com.empty;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private EditText et_number;
private EditText et_password;
private Button btn_login;
private Button btn_chongzhi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
textView = (TextView) findViewById(R.id.textView);
et_number = (EditText) findViewById(R.id.et_number);
et_password = (EditText) findViewById(R.id.et_password);
btn_login = (Button) findViewById(R.id.btn_login);
btn_chongzhi = (Button) findViewById(R.id.btn_chongzhi);
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (et_number.getText().toString().equals("admin") && et_password.getText().toString().equals("123456")) {
//textView.setText("登录成功");
Intent intent = new Intent(MainActivity.this,ArticleListActivity.class);
Bundle bundle = new Bundle();
bundle.putString("name",et_number.getText().toString());
bundle.putString("password",et_password.getText().toString());
//intent.putExtra("Message","jmptest");
intent.putExtra("Message",bundle);
startActivity(intent);
} else {
textView.setText("登陆失败,用户名或密码错误!");
}
}
});
btn_chongzhi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
et_number.setText("");
et_password.setText("");
textView.setText("");
}
});
}
}
ArticleListActivity.java
package com.empty;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
public class ArticleListActivity extends AppCompatActivity {
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article_list);
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("Message");
//Bundle bundle = intent.getExtras();
String name = bundle.getString("name");
String password = bundle.getString("password");
//String message = intent.getStringExtra("Message");
lv = findViewById(R.id.lv);
String [] names = {"jmpclass1","jmpclass2","jmpclass3","jmpclass4","jmpclass5"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ArticleListActivity.this, android.R.layout.simple_list_item_single_choice,names);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
lv.setAdapter(adapter);
}
}
2. xml
login.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E6E6"
android:orientation="vertical">
<ImageView
android:id="@+id/iv"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="@drawable/ic_launcher_foreground"/>
<LinearLayout
android:id="@+id/ll_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/iv"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#ffffff">
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="账号:"
android:textColor="#000"
android:textSize="20sp"/>
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@null"
android:padding="10dp"/>
LinearLayout>
<LinearLayout
android:id="@+id/ll_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll_number"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff">
<TextView
android:id="@+id/tv_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="密码:"
android:textColor="#000"
android:textSize="20sp"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/tv_password"
android:background="@null"
android:inputType="textPassword"
android:padding="10dp"/>
LinearLayout>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll_password"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:background="#3C8DC4"
android:text="登录"
android:textColor="#ffffff"
android:textSize="20sp"/>
<Button
android:id="@+id/btn_chongzhi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btn_login"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#3C8DC4"
android:text="重置"
android:textColor="#ffffff"
android:textSize="20sp"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:textColor="#000"
android:textSize="20sp"
android:text=""
android:layout_below="@+id/btn_chongzhi"
android:layout_alignLeft="@+id/btn_login"
android:layout_alignStart="@+id/btn_login"/>
RelativeLayout>
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
androidx.constraintlayout.widget.ConstraintLayout>
activity_article_list.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ArticleListActivity">
<Button android:id="@+id/btnReturn"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="return"/>
<ListView android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent">ListView>
LinearLayout>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.empty">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Empty">
<activity
android:name=".ArticleListActivity"
android:exported="true"/>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
intent-filter>
activity>
application>
manifest>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)