parent
f8f5f73185
commit
6539cc3c27
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -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
|
||||
// }
|
||||
// }
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
@ -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…
Reference in new issue