parent
81a1786f55
commit
4591651369
@ -0,0 +1,18 @@
|
|||||||
|
package hunnu.sj.raise_money;
|
||||||
|
|
||||||
|
public class News {
|
||||||
|
private String title;
|
||||||
|
private String content;
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package hunnu.sj.raise_money;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NewsAdapter extends ArrayAdapter<News> {
|
||||||
|
private int resourceId;
|
||||||
|
public NewsAdapter(Context context, int textViewResourceId, List<News> objects) {
|
||||||
|
super(context, textViewResourceId, objects);
|
||||||
|
resourceId = textViewResourceId;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
News news = getItem(position);
|
||||||
|
View view;
|
||||||
|
if (convertView == null) {
|
||||||
|
view = LayoutInflater.from(getContext()).inflate(resourceId, null);
|
||||||
|
} else {
|
||||||
|
view = convertView;
|
||||||
|
}
|
||||||
|
TextView newsTitleText =(TextView) view.findViewById(R.id.news_title);
|
||||||
|
newsTitleText.setText(news.getTitle());
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package hunnu.sj.raise_money;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Window;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
public class NewsContentActivity extends AppCompatActivity{
|
||||||
|
public static void actionStart(Context context, String newsTitle, String newsContent) {
|
||||||
|
Intent intent = new Intent(context, NewsContentActivity.class);
|
||||||
|
intent.putExtra("news_title", newsTitle);
|
||||||
|
intent.putExtra("news_content", newsContent);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
Log.v("news_title","here");
|
||||||
|
setContentView(R.layout.news_content);
|
||||||
|
String newsTitle = getIntent().getStringExtra("news_title"); // 获取传入的新闻标题
|
||||||
|
String newsContent = getIntent().getStringExtra("news_content"); // 获取传入的新闻内容
|
||||||
|
NewsContentFragment newsContentFragment = (NewsContentFragment)
|
||||||
|
getFragmentManager().findFragmentById(R.id.news_content_fragment);
|
||||||
|
newsContentFragment.refresh(newsTitle, newsContent); // 刷新NewsContentFragment界面
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package hunnu.sj.raise_money;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
|
||||||
|
public class NewsContentFragment extends Fragment {
|
||||||
|
private View view;
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
view = inflater.inflate(R.layout.fragment_news_content, container, false);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
public NewsContentFragment(){}
|
||||||
|
public void refresh(String newsTitle, String newsContent) {
|
||||||
|
View visibilityLayout = view.findViewById(R.id.visibility_layout);
|
||||||
|
visibilityLayout.setVisibility(View.VISIBLE);
|
||||||
|
TextView newsTitleText = (TextView) view.findViewById (R.id.news_title);
|
||||||
|
TextView newsContentText = (TextView) view.findViewById(R.id.news_content);
|
||||||
|
newsTitleText.setText(newsTitle); // 刷新新闻的标题
|
||||||
|
newsContentText.setText(newsContent); // 刷新新闻的内容
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package hunnu.sj.raise_money.dummy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for providing sample content for user interfaces created by
|
||||||
|
* Android template wizards.
|
||||||
|
* <p>
|
||||||
|
* TODO: Replace all uses of this class before publishing your app.
|
||||||
|
*/
|
||||||
|
public class DummyContent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of sample (dummy) items.
|
||||||
|
*/
|
||||||
|
public static final List<DummyItem> ITEMS = new ArrayList<DummyItem>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map of sample (dummy) items, by ID.
|
||||||
|
*/
|
||||||
|
public static final Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();
|
||||||
|
|
||||||
|
private static final int COUNT = 25;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Add some sample items.
|
||||||
|
for (int i = 1; i <= COUNT; i++) {
|
||||||
|
addItem(createDummyItem(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addItem(DummyItem item) {
|
||||||
|
ITEMS.add(item);
|
||||||
|
ITEM_MAP.put(item.id, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DummyItem createDummyItem(int position) {
|
||||||
|
return new DummyItem(String.valueOf(position), "Item " + position, makeDetails(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String makeDetails(int position) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("Details about Item: ").append(position);
|
||||||
|
for (int i = 0; i < position; i++) {
|
||||||
|
builder.append("\nMore details information here.");
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A dummy item representing a piece of content.
|
||||||
|
*/
|
||||||
|
public static class DummyItem {
|
||||||
|
public final String id;
|
||||||
|
public final String content;
|
||||||
|
public final String details;
|
||||||
|
|
||||||
|
public DummyItem(String id, String content, String details) {
|
||||||
|
this.id = id;
|
||||||
|
this.content = content;
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
|
tools:context=".NewsContentActivity">
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,26 @@
|
|||||||
|
<?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" >
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/visibility_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="invisible" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/news_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:textSize="20sp" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/news_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="15dp"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</RelativeLayout>
|
@ -0,0 +1,11 @@
|
|||||||
|
<?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"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/news_title_list_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" >
|
||||||
|
</ListView>
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,11 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/news_content_fragment"
|
||||||
|
android:name="hunnu.sj.raise_money.NewsContentFragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,17 @@
|
|||||||
|
<?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"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/news_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:paddingTop="15dp"
|
||||||
|
android:paddingBottom="15dp"/>
|
||||||
|
</LinearLayout>
|
Loading…
Reference in new issue