我正在尝试学习如何从mySQL加载回收器视图。遵循了一些教程,但是显示了回收站视图,但没有任何内容。所以我不确定我做错了什么。
我想做的是,我有一个应用程序,可以让我拍照并发送一些输入到我的xammp服务器。然后,此应用将使您可以使用回收站视图来查看图片和一些文本字段,最终可以单击它们以获取更多信息。最终,我想将其转变为我提供给当地动物收容所之类的应用程序。他们在一个应用程序上为他们的狗拍照,然后人们可以下载另一个应用程序并查看可用的狗。
现在,我知道图像内容被弄乱了,因此我将其记录下来。我的“ url”是我服务器上的路径,而不是http url,我还没有弄清楚如何使其正常工作,但我知道它不适用于毕加索(我想这样做,我对此有些陌生),仍在学习,这就是为什么有毕加索的东西存在的原因。
TL; DR 但是我无法让recyclerview在页面上显示任何数据,也就是firsname,lastname。
这是我的index.php
$app->get('/getprofilepic', function(request $request, Response $response){
$db = new profilepic;
$profiledata = $db->getprofilepic();
$response->getBody()>write(json_encode(array("profiledata"=>$profiledata)));
});
这是我的php个人资料
private $con;
function __construct(){
require_once dirname(__FILE__) . '/DbConnect.php';
$db = new DbConnect;
$this->con = $db->connect();
}
public function getprofilepic(){
$stmt = $this->con->prepare("SELECT doginfohometab1db.ID, doginfohometab1db.firstnametxt, doginfohometab1db.lastnametxt, profilepicdb.picurl FROM doginfohometab1db LEFT JOIN profilepicdb ON doginfohometab1db.ID = profilepicdb.ID WHERE doginfohometab1db.ID in(SELECT ID FROM doginfohometab1db WHERE NOT EXISTS (SELECT ID FROM dogdischargeinfohometab1db WHERE doginfohometab1db.id = dogdischargeinfohometab1db.id))");
$stmt->execute();
$stmt->bind_result($ID, $firstnametxt, $lastnametxt, $picurl);
$profiledata = array();
while($stmt->fetch()){
$temp = array();
$temp ['ID'] = $ID;
$temp ['firstnametxt'] = $firstnametxt;
$temp ['lastnametxt'] = $lastnametxt;
$temp ['picurl'] = $picurl;
array_push($profiledata, $temp);
}
return $profiledata;
}
}
这是我的邮递员回复
{"profiledata":
[{“ ID”:“ hvg766khhv”,“ firstnametxt”:“ hvg”,“ lastnametxt”:“ khhv”,“ picurl”:“ C:\ xampp \ htdocs \ pathways1 \ includes / uploads / 1535685930271.jpg “},{” ID“:” jdjd676jdjf“,” firstnametxt“:” jdjd“,” lastnametxt“:” jdjf“,” picurl“:” C:\ xapp \ htdocs \ pathways1 \ includes / uploads / 1535686965814.jpg“ }]}
这是我的api调用
@GET("getprofilepic")
Call<PtList> PtList();
PtList类
import java.util.ArrayList;
public class PtList {
@SerializedName("ptList")
private ArrayList<dogdata> ptList;
public ArrayList<dogdata> getdogArrayList(){
return ptList;
}
public void setdogArrayList(ArrayList<dogdata> dogArrayList){
this.ptList = dogArrayList;
}
}
这是我的dogdata类
public class dogdata {
@SerializedName("firstnametxt")
private String firstnametxt;
@SerializedName("lastnametxt")
private String lastnametxt;
@SerializedName("ID")
private String ID;
private boolean isSelected = false;
@SerializedName("picurl")
private String picurl;
dogdata(String firstnametxt, String lastnametxt, String ID, String picurl){
this.ID = ID;
this.firstnametxt = firstnametxt;
this.lastnametxt = lastnametxt;
this.picurl = picurl;
}
public String getID(){
return ID;
}
public void setID(String ID){
this.ID = ID;
}
public String getPicurl(){
return picurl;
}
public void setPicurl (String picurl){
this.picurl = picurl;
}
public String getFirstnametxt(){
return firstnametxt;
}
public void setFirstnametxt(String firstnametxt){
this.firstnametxt = firstnametxt;
}
public String getLastnametxt(){
return lastnametxt;
}
public void setLastnametxt(String lastnametxt){
this.lastnametxt = lastnametxt;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
public boolean isSelected() {
return isSelected;
}
}
这是我的活动课程
public class TreatmentMain extends AppCompatActivity implements View.OnClickListener {
private RecyclerView mptRecyclerView;
private RecyclerView.Adapter mptAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_treatment_main);
downdogdata();
}
private void generatePtList(ArrayList<dogdata> ptList){
mptRecyclerView = (RecyclerView) findViewById(R.id.ptrecycler_view);
mptAdapter = new TreatmentAdapter(this, ptList);
RecyclerView.LayoutManager ptmanager = new LinearLayoutManager(TreatmentMain.this);
mptRecyclerView.setHasFixedSize(true);
mptRecyclerView.setLayoutManager(ptmanager);
mptRecyclerView.setAdapter(mptAdapter);
}
public void downdogdata() {
Call<PtList> call = RetrofitClient.getInstance().getAPIService().PtList();
call.enqueue(new Callback<PtList>() {
@Override
public void onResponse(Call<PtList> call, Response<PtList> response) {
if (response.code() == 200) {
generatePtList(response.body().getdogArrayList());
}
else if (response.code() == 422)
Toast.makeText(TreatmentMain.this, "Opps your code don't work bro", Toast.LENGTH_LONG).show();
{
} }
@Override
public void onFailure(Call<PtList> call, Throwable t) {
Toast.makeText(TreatmentMain.this, "Opps your code don't work bro on failure toast", Toast.LENGTH_LONG).show();
}
});
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.txmainback:
Intent txmainback = new Intent(this, MainActivity.class);
startActivity(txmainback);
}
}
}
最后是我的适配器类
public class TreatmentAdapter extends RecyclerView.Adapter<TreatmentAdapter.MyptViewHolder> {
private ArrayList<dogdata> mptModelList;
private myptAdapterListener mptListener;
String ID;
Context mptcontext;
public interface myptAdapterListener{
void ontextClick(int position);
}
public TreatmentAdapter(Context context, ArrayList<dogdata> mptModelList) {
this.mptModelList = mptModelList;
mptcontext = context;
}
@Override
public MyptViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.treatmentrow, parent, false);
return new MyptViewHolder(view);
}
@Override
public void onBindViewHolder(final MyptViewHolder holder, final int position) {
final dogdata ptmodel = mptModelList.get(position);
holder.Treatmentfirstname.setText(ptmodel.getFirstnametxt());
holder.Treatmentlastname.setText(ptmodel.getLastnametxt());
// Picasso.get().load(ptmodel.getPicurl()).fit().centerCrop().error(R.drawable.ic_launcher_foreground).into(holder.ptreatmentprofile);
ID = ptmodel.getID();
holder.view.setBackgroundColor(ptmodel.isSelected() ? Color.CYAN: Color.WHITE);
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ptmodel.setSelected(!ptmodel.isSelected());
holder.view.setBackgroundColor(ptmodel.isSelected() ? Color.GREEN : Color.WHITE);
mptListener.ontextClick(position);
}
});
}
@Override
public int getItemCount() {
return mptModelList == null ? 0 : mptModelList.size();
}
public class MyptViewHolder extends RecyclerView.ViewHolder {
private View view;
private TextView Treatmentfirstname;
private TextView Treatmentlastname;
private ImageView ptreatmentprofile;
public MyptViewHolder(final View View) {
super(View);
view = View;
Treatmentfirstname = (TextView) View.findViewById(R.id.Treatmentfirstname);
Treatmentlastname =(TextView) View.findViewById(R.id.Treatmentlastname);
ptreatmentprofile = (ImageView) View.findViewById(R.id.ptreatmentprofile);
}
}
}