第二阶段(冲刺八)
实现数据显示
1.整体书籍展示
2对应书籍章节展示
showbookactivity
package com.lh.std_everything.ui.home.hometype.studyshare.share; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.lh.std_everything.R; public class ShowBookActivity extends AppCompatActivity{ public TextView textViewbookname,textViewbookauthor,textViewbookpublish,textViewbookusername; public ImageView bookphoto; public LinearLayout lin_tree; public Bundle bundle; public String arr[]={"begin","one","two","three","four","five","six","seven","eight","nine","ten","others"}; public String harr[]={"heh","第一章","第二章","第三章","第四章","第五章","第六章","第七章","第八章","第九章","第十章","其他"}; public Integer iarr[]={0,1,2,3,4,5,6,7,8,9,11}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_book); init(); lin_tree.setOrientation(LinearLayout.VERTICAL); lin_tree.removeAllViews(); if(bundle!=null) { for(int i=1;i<=11;i++) { if(bundle.containsKey(arr[i])) { String key=bundle.getString(arr[i]); TextView zhangjie=new TextView(this); zhangjie.setText(harr[i]); Log.i("章节展示:", ""+harr[i]); zhangjie.setId(iarr[i]); zhangjie.setTextSize(20); zhangjie.setPadding(10,10,0,0); lin_tree.addView(zhangjie); zhangjie.setOnClickListener(v -> { Bundle b1=new Bundle(); b1.putString("photos",key); Intent intent =new Intent(ShowBookActivity.this,ShowBookAnswerActivity.class); intent.putExtras(b1); startActivity(intent); }); } } } } public void init() { textViewbookauthor=findViewById(R.id.tv_bookauthor); textViewbookname=findViewById(R.id.tv_bookname); textViewbookpublish=findViewById(R.id.tv_bookpublish); textViewbookusername=findViewById(R.id.tv_username); bookphoto=findViewById(R.id.bookphoto); lin_tree=findViewById(R.id.lin_tree); bundle = getIntent().getExtras(); if(bundle!=null) { Log.i("接收端的bundle的username", bundle.getString("username")); textViewbookusername.setText("上传者:"+bundle.getString("username")); textViewbookpublish.setText("出版社:"+bundle.getString("bookpublish")); textViewbookname.setText(bundle.getString("bookname")); textViewbookauthor.setText("作者:"+bundle.getString("bookauthor")); String urls[]=bundle.getString("head").split("\\$"); RequestOptions options = new RequestOptions() .error(R.drawable.error) .placeholder(R.drawable.loading); if(urls.length!=0) { for(int i=0;i<urls.length;i++) { if(!urls[i].equals("null")) { Log.i("url",urls[i]); Glide.with(this) .load(urls[i]) .apply(options) .into(bookphoto); break; } } } } } }
3对应章节答案展示
showbookanswerActivity
package com.lh.std_everything.ui.home.hometype.studyshare.share; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.lh.std_everything.R; import com.lh.std_everything.ui.home.hometype.adapter.GridViewAdapter.GridViewAdapter; import com.lh.std_everything.ui.home.hometype.news.shownews.ShowNewsActivity; import com.lxj.xpopup.XPopup; public class ShowBookAnswerActivity extends AppCompatActivity { public LinearLayout lin_imgs; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_book_answer); Bundle bundle = getIntent().getExtras(); String urls[]=bundle.getString("photos").split("\\$"); lin_imgs=findViewById(R.id.lin_imgs); RequestOptions options = new RequestOptions() .error(R.drawable.error) .placeholder(R.drawable.loading); if(urls.length!=0) { for(int i=0;i<urls.length;i++) { if(!urls[i].equals("null")) { ImageView item=new ImageView(this); Log.i("url",urls[i]); Glide.with(this) .load(urls[i]) .apply(options) .into(item); int finalI = i; item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new XPopup.Builder(ShowBookAnswerActivity.this) .asImageViewer(item,urls[finalI],new GridViewAdapter.ImageLoader()) .show(); } }); lin_imgs.addView(item); } } } } }
李浩:
今日将app打包安装到手机上,出现了部分不适配情况。
明日任务:对排版进行优化,使其适配手机。