今天做了什么:
完成了对于团队作业中社区的点击事件,跳转到具体界面
package com.hui.testend.community;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.hui.testend.R;
import com.hui.testend.list.ItemBean;
import com.hui.testend.list.RecordAdapter;
import com.hui.testend.list.recordBean;
import com.hui.testend.mytool.Dao;
import com.hui.testend.mytool.ImageUtil;
import com.hui.testend.recongnize.baiduapi;
import java.util.Base64;
import java.util.List;
public class displayActivity extends AppCompatActivity implements View.OnClickListener , AdapterView.OnItemClickListener {
TextView tv_comm_title,tv_comm_content;
ImageView iv_comm_img;
EditText ed_bottom_comm;
Button btn_add_comment;
ListView list_comm;
Handler mainhandler;
Dao dao=new Dao();
Toolbar toolbar;
RecordAdapter recordAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
System.out.println(999999);
init();
System.out.println(888888);
initdata(getid());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemid= item.getItemId();
switch(itemid){
case R.id.menu_main:
Intent intent=new Intent(this, baiduapi.class);
startActivity(intent);
case R.id.menu_add_comm:
Intent intent1=new Intent(this, addcontent.class);
startActivity(intent1);
}
return super.onOptionsItemSelected(item);
}
public void init(){
tv_comm_title=findViewById(R.id.tv_comm_title);
tv_comm_content=findViewById(R.id.tv_comm_content);
iv_comm_img=findViewById(R.id.iv_comm_img);
ed_bottom_comm=findViewById(R.id.ed_bottom_comm);
list_comm=findViewById(R.id.list_comm);
btn_add_comment=findViewById(R.id.btn_add_comment);
btn_add_comment.setOnClickListener(this);
mainhandler=new Handler(getMainLooper());
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public int getid(){
Intent intent=getIntent();
return intent.getIntExtra("id",3);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_add_comment:
String edittext=ed_bottom_comm.getText().toString().trim();
addcomment(edittext,String.valueOf(getid()));
break;
}
}
public void initdata(int id){
new Thread(new Runnable() {
@Override
public void run() {
ItemBean item=new ItemBean();
item=dao.selectid(id);
ItemBean finalItem = item;
recordBean recordBean=new recordBean();
List<com.hui.testend.list.recordBean> records= dao.getcomments(String.valueOf(id));
mainhandler.post(new Runnable() {
@Override
public void run() {
iv_comm_img.setImageBitmap(ImageUtil.base64ToImage(Base64.getEncoder().encodeToString(finalItem.getImg())));
tv_comm_title.setText(tv_comm_title.getText().toString()+ finalItem.getTitle());
tv_comm_content.setText(tv_comm_content.getText().toString()+ finalItem.getContent());
recordAdapter=new RecordAdapter(displayActivity.this,records);
list_comm.setAdapter(recordAdapter);
System.out.println(finalItem.getTitle()+6666);
}
});
}
}).start();
}
public void addcomment(String edittext1,String id1){
new Thread(new Runnable() {
@Override
public void run() {
dao.add_comment(edittext1,id1);
mainhandler.post(new Runnable() {
@Override
public void run() {
}
});
}
}).start();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.hui.testend.R;
import com.hui.testend.list.ItemBean;
import com.hui.testend.list.RecordAdapter;
import com.hui.testend.list.recordBean;
import com.hui.testend.mytool.Dao;
import com.hui.testend.mytool.ImageUtil;
import com.hui.testend.recongnize.baiduapi;
import java.util.Base64;
import java.util.List;
public class displayActivity extends AppCompatActivity implements View.OnClickListener , AdapterView.OnItemClickListener {
TextView tv_comm_title,tv_comm_content;
ImageView iv_comm_img;
EditText ed_bottom_comm;
Button btn_add_comment;
ListView list_comm;
Handler mainhandler;
Dao dao=new Dao();
Toolbar toolbar;
RecordAdapter recordAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
System.out.println(999999);
init();
System.out.println(888888);
initdata(getid());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemid= item.getItemId();
switch(itemid){
case R.id.menu_main:
Intent intent=new Intent(this, baiduapi.class);
startActivity(intent);
case R.id.menu_add_comm:
Intent intent1=new Intent(this, addcontent.class);
startActivity(intent1);
}
return super.onOptionsItemSelected(item);
}
public void init(){
tv_comm_title=findViewById(R.id.tv_comm_title);
tv_comm_content=findViewById(R.id.tv_comm_content);
iv_comm_img=findViewById(R.id.iv_comm_img);
ed_bottom_comm=findViewById(R.id.ed_bottom_comm);
list_comm=findViewById(R.id.list_comm);
btn_add_comment=findViewById(R.id.btn_add_comment);
btn_add_comment.setOnClickListener(this);
mainhandler=new Handler(getMainLooper());
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public int getid(){
Intent intent=getIntent();
return intent.getIntExtra("id",3);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_add_comment:
String edittext=ed_bottom_comm.getText().toString().trim();
addcomment(edittext,String.valueOf(getid()));
break;
}
}
public void initdata(int id){
new Thread(new Runnable() {
@Override
public void run() {
ItemBean item=new ItemBean();
item=dao.selectid(id);
ItemBean finalItem = item;
recordBean recordBean=new recordBean();
List<com.hui.testend.list.recordBean> records= dao.getcomments(String.valueOf(id));
mainhandler.post(new Runnable() {
@Override
public void run() {
iv_comm_img.setImageBitmap(ImageUtil.base64ToImage(Base64.getEncoder().encodeToString(finalItem.getImg())));
tv_comm_title.setText(tv_comm_title.getText().toString()+ finalItem.getTitle());
tv_comm_content.setText(tv_comm_content.getText().toString()+ finalItem.getContent());
recordAdapter=new RecordAdapter(displayActivity.this,records);
list_comm.setAdapter(recordAdapter);
System.out.println(finalItem.getTitle()+6666);
}
});
}
}).start();
}
public void addcomment(String edittext1,String id1){
new Thread(new Runnable() {
@Override
public void run() {
dao.add_comment(edittext1,id1);
mainhandler.post(new Runnable() {
@Override
public void run() {
}
});
}
}).start();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
<?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"
tools:context=".community.displayActivity"
android:orientation="vertical"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/green_700"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_comm_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题:"
android:textSize="28sp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_comm_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="内容:"
android:textSize="28sp"
android:textStyle="bold"/>
</LinearLayout>
<ImageView
android:id="@+id/iv_comm_img"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/img"
android:scaleType="centerCrop"/>
<LinearLayout
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<ListView
android:id="@+id/list_comm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:padding="5dp"
android:id="@+id/ed_bottom_comm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="请输入评论"/>
<Button
android:id="@+id/btn_add_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交"/>
</LinearLayout>
</LinearLayout>
<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"
tools:context=".community.displayActivity"
android:orientation="vertical"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/green_700"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_comm_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题:"
android:textSize="28sp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_comm_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="内容:"
android:textSize="28sp"
android:textStyle="bold"/>
</LinearLayout>
<ImageView
android:id="@+id/iv_comm_img"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/img"
android:scaleType="centerCrop"/>
<LinearLayout
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<ListView
android:id="@+id/list_comm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:padding="5dp"
android:id="@+id/ed_bottom_comm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="请输入评论"/>
<Button
android:id="@+id/btn_add_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交"/>
</LinearLayout>
</LinearLayout>
遇到了什么困难:
跳转怎么传递图片数据,传递他的uri
明天准备做什么:
继续完成作业
代码量 80行
时间 0.5小时