This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1270 from 18CS118/master
- Loading branch information
Showing
11 changed files
with
247 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
students/sec1814080911118/app/src/main/java/edu/hzuapps/pyq/listview/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package edu.hzuapps.pyq.listview; | ||
|
||
public class Message { | ||
private String name; | ||
private int imageId; | ||
|
||
public Message(String name,int imageId){ | ||
this.name=name; | ||
this.imageId=imageId; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setImageId(int imageId) { | ||
this.imageId = imageId; | ||
} | ||
|
||
public String getName(){ | ||
return name; | ||
} | ||
|
||
public int getImageId(){ | ||
return imageId; | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
students/sec1814080911118/app/src/main/java/edu/hzuapps/pyq/listview/MessageAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package edu.hzuapps.pyq.listview; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
import android.widget.ArrayAdapter; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import java.util.List; | ||
|
||
import edu.hzuapps.pyq.R; | ||
import edu.hzuapps.pyq.listview.Message; | ||
|
||
public class MessageAdapter extends ArrayAdapter<Message> { | ||
private int resourceId; | ||
|
||
// 适配器的构造函数,把要适配的数据传入这里 | ||
public MessageAdapter(Context context, int textViewResourceId, List<Message> objects){ | ||
super(context,textViewResourceId,objects); | ||
resourceId=textViewResourceId; | ||
} | ||
|
||
// convertView 参数用于将之前加载好的布局进行缓存 | ||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent){ | ||
Message message=getItem(position); //获取当前项的Fruit实例 | ||
|
||
// 加个判断,以免ListView每次滚动时都要重新加载布局,以提高运行效率 | ||
View view; | ||
ViewHolder viewHolder; | ||
if (convertView==null){ | ||
|
||
// 避免ListView每次滚动时都要重新加载布局,以提高运行效率 | ||
view=LayoutInflater.from(getContext()).inflate(resourceId,parent,false); | ||
|
||
// 避免每次调用getView()时都要重新获取控件实例 | ||
viewHolder=new ViewHolder(); | ||
viewHolder.messageName=view.findViewById(R.id.message_content); | ||
viewHolder.messageImage=view.findViewById(R.id.message_image); | ||
|
||
// 将ViewHolder存储在View中(即将控件的实例存储在其中) | ||
view.setTag(viewHolder); | ||
} else{ | ||
view=convertView; | ||
viewHolder=(ViewHolder) view.getTag(); | ||
} | ||
|
||
// 获取控件实例,并调用set...方法使其显示出来 | ||
viewHolder.messageImage.setImageResource(message.getImageId()); | ||
viewHolder.messageName.setText(message.getName()); | ||
return view; | ||
} | ||
|
||
// 定义一个内部类,用于对控件的实例进行缓存 | ||
class ViewHolder{ | ||
ImageView messageImage; | ||
TextView messageName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 14 additions & 3 deletions
17
students/sec1814080911118/app/src/main/res/layout/activity_send_pyq.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
<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" | ||
tools:context=".SendPyqActivity"> | ||
android:orientation="vertical"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
<EditText | ||
android:id="@+id/content" | ||
android:layout_width="match_parent" | ||
android:layout_height="100sp" | ||
android:layout_marginTop="200sp"/> | ||
<Button | ||
android:id="@+id/sendBtn" | ||
android:layout_width="match_parent" | ||
android:layout_height="50sp" | ||
android:text="@string/submit"/> | ||
|
||
</LinearLayout> |
32 changes: 32 additions & 0 deletions
32
students/sec1814080911118/app/src/main/res/layout/message_item.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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"> | ||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="0.5dp" | ||
android:background="#97a791"/> | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="horizontal"> | ||
<ImageView | ||
android:id="@+id/message_image" | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:layout_marginTop="10sp" | ||
android:layout_marginBottom="10sp"/> | ||
|
||
<TextView | ||
android:id="@+id/message_content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="10sp" | ||
android:layout_marginBottom="10sp" | ||
android:layout_gravity="center_vertical" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginStart="10dp" /> | ||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#6200EE</color> | ||
<color name="colorPrimaryDark">#3700B3</color> | ||
<color name="colorAccent">#03DAC5</color> | ||
</resources> |
2 changes: 2 additions & 0 deletions
2
students/sec1814080911118/app/src/main/res/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<resources> | ||
<string name="app_name">PYQ</string> | ||
<string name="look_pyq">发朋友圈</string> | ||
<string name="submit">提交</string> | ||
</resources> |