第三次实验

master
tangxi 2 years ago
parent f8f5f73185
commit 6539cc3c27

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" /> <bytecodeTargetLevel target="11" />
</component> </component>
</project> </project>

@ -8,6 +8,7 @@
<option name="testRunner" value="GRADLE" /> <option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="jbr-11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -23,6 +23,10 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.4.+'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

@ -9,15 +9,24 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".MainActivity"> <activity
android:name=".TitleFragment"
android:exported="false" />
<activity
android:name=".ContentFragment"
android:exported="false" />
<activity
android:name=".activity.activity.GoodsActivity"
android:exported="false" />
<activity android:name=".activity.activity.MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".RegisterActivity"></activity> <activity android:name=".activity.activity.RegisterActivity" />
<activity android:name=".UserActivity" /> <activity android:name=".activity.activity.UserActivity" />
</application> </application>
</manifest> </manifest>

@ -0,0 +1,43 @@
package com.example.Cat.activity.activity;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.Cat.R;
import com.example.Cat.activity.activity.MainActivity;
public class ContentFragment extends Fragment {
private View view;
private TextView text1,text2;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//获取布局文件
view=inflater.inflate(R.layout.content_layout,container,false);
if (view!=null){
init();
}
//获取activity中设置的文字
setText(((MainActivity)getActivity()).getSettingText()[0]);
return view;
}
private void init() {
text1=(TextView)view.findViewById(R.id.show_title);
text2=(TextView)view.findViewById(R.id.show_content);
}
public void setText(String[] text) {
Log.i("news",text[0]);
text1.setText(text[0]);
text2.setText(text[1]);
}
}

@ -0,0 +1,24 @@
package com.example.Cat.activity.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.example.Cat.R;
public class GoodsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.production);
}
// @Override
// public void onClick(View v){
// switch(v.getId()){
// case
// }
// }
}

@ -1,4 +1,4 @@
package com.example.Cat; package com.example.Cat.activity.activity;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -8,10 +8,25 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import com.example.Cat.R;
public class MainActivity extends AppCompatActivity implements View.OnClickListener { public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button registerButton, loginButton; private Button registerButton, loginButton;
private EditText usernameText, paswdEdit; private EditText usernameText, paswdEdit;
private String tilte[]={"标题一","标题二","标题三"};
private String settingText[][]={{"标题一","标题一的内容"},{"标题二","标题二的内容"},{"标题三","标题三的内容"}};
//获取标题数组的方法
public String[] getTilte(){
return tilte;
}
//获取标题和内容
public String[][] getSettingText(){
return settingText;
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

@ -1,4 +1,4 @@
package com.example.Cat; package com.example.Cat.activity.activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
@ -13,6 +13,7 @@ import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.example.Cat.R;
import com.lljjcoder.citypickerview.widget.CityPicker; import com.lljjcoder.citypickerview.widget.CityPicker;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener { public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {

@ -0,0 +1,84 @@
package com.example.Cat.activity.activity;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.example.Cat.R;
public class TitleFragment extends Fragment {
private View view;
private String[] title;
private String[][] contents;
private ListView listView;
// private String settingText[][]={{"标题一","标题一的内容"},{"标题二","标题二的内容"},{"标题三","标题三的内容"}};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view=inflater.inflate(R.layout.title_layout,container,false);
//获取Activty实例对象
MainActivity activity=(MainActivity)getActivity();
//获取Activty中的标题
title=activity.getTilte();
//获取Activty中的标题和内容
contents=activity.getSettingText();
if (view!=null){
init();
}
//为listview添加监听
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//通过activity实例获取另一个Fragment对象
com.example.Cat.activity.activity.ContentFragment content=(com.example.Cat.activity.activity.ContentFragment)((MainActivity)getActivity())
.getSupportFragmentManager().findFragmentById(R.id.setcontent);
content.setText(contents[i]);
}
});
return view;
}
private void init() {
listView=(ListView)view.findViewById(R.id.titlelist);
if (title!=null){
listView.setAdapter(new MyAdapter());
}
}
//适配器
class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
return title.length;
}
@Override
public Object getItem(int i) {
return title[i];
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view=View.inflate(getActivity(), R.layout.title_item_layout,null);
TextView titletext=(TextView)view.findViewById(R.id.titles);
titletext.setText(title[i]);
return view;
}
}
}

@ -1,4 +1,4 @@
package com.example.Cat; package com.example.Cat.activity.activity;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
@ -10,10 +10,12 @@ import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class UserActivity extends Activity { import com.example.Cat.R;
public class UserActivity extends Activity implements View.OnClickListener{
private ImageView userIconImage; private ImageView userIconImage;
private TextView usernameText, userSexText, userCityText; private TextView usernameText, userSexText, userCityText;
private LinearLayout usernameLine, userSexline, userCityLine, userPayLine, userSettingLine, userGeneralLine; private LinearLayout usernameLine, userSexline, userCityLine, userPayLine, userSettingLine, userGeneralLine,userProductLine;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -36,6 +38,8 @@ public class UserActivity extends Activity {
userPayLine = findViewById(R.id.user_pay); userPayLine = findViewById(R.id.user_pay);
userSettingLine = findViewById(R.id.user_setting); userSettingLine = findViewById(R.id.user_setting);
userGeneralLine = findViewById(R.id.user_general); userGeneralLine = findViewById(R.id.user_general);
userProductLine = findViewById(R.id.user_product);
userProductLine.setOnClickListener(this);
setData(); setData();
} }
@ -49,8 +53,17 @@ public class UserActivity extends Activity {
userSexText.setText(String.format("性别:%s", bundle.getString("sex"))); userSexText.setText(String.format("性别:%s", bundle.getString("sex")));
userCityText.setText(String.format("城市:%s", bundle.getString("city"))); userCityText.setText(String.format("城市:%s", bundle.getString("city")));
} }
public void click(View v) { @Override
Intent intent = new Intent(this, MainActivity.class); public void onClick(View v) {
startActivity(intent); switch (v.getId()) {
case R.id.exit:
Intent intent1 = new Intent(this, MainActivity.class);
startActivity(intent1);
break;
case R.id.user_product:
Intent intent2 = new Intent(this,TitleFragment.class);
startActivity(intent2);
break;
}
} }
} }

@ -5,7 +5,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".activity.activity.MainActivity">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".ContentFragment">
<TextView
android:id="@+id/show_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="显示新闻标题" />
<TextView
android:id="@+id/show_content"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="显示新闻内容" />
</LinearLayout>

@ -162,19 +162,21 @@
<!--查看商品--> <!--查看商品-->
<LinearLayout <LinearLayout
android:id="@+id/user_searchProduct" android:id="@+id/user_product"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="#FFF" android:background="#FFF"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:orientation="horizontal"> android:orientation="horizontal"
android:clickable="true"
>
<TextView <TextView
android:layout_height="35dp" android:layout_height="35dp"
android:layout_weight="1" android:layout_weight="1"
android:drawableLeft="@drawable/search" android:drawableLeft="@drawable/search"
android:textColor="#000" android:textColor="#000"
android:text="查看商品" android:text="查看宠物商品"
android:gravity="center_vertical" android:gravity="center_vertical"
android:drawablePadding="8dp" android:drawablePadding="8dp"
android:textSize="14sp" android:textSize="14sp"

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/goodsList"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">
<!--标题-->
<FrameLayout
android:id="@+id/settitle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
</FrameLayout>
<!--内容-->
<FrameLayout
android:id="@+id/setcontent"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/titles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize ="16sp"/>
</LinearLayout>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".TitleFragment">
<!--用来展示新闻标题列表-->
<ListView
android:id="@+id/titlelist"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Loading…
Cancel
Save