在recyclerview中显示特定信息 [英] Display specific information in recyclerview

查看:69
本文介绍了在recyclerview中显示特定信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在花时间学习RecyclerView并将数据显示在其中。但我遇到了一个问题,我想咨询你们如何在RecyclerView中搜索。



我打算做的是会有一个EditText和按钮。当应用程序加载时,RecyclerView上将没有数据。但只有当我在EditText中输入要搜索的内容然后单击按钮时。然后只有应用程序才能从数据库中获取信息并在RecyclerView中显示。



这是我的php文件



 <?php  

$ page = $ _GET [' page'];

$ superHero = $ _GET [' superHero'];

$ start = 0 ;

$ limit = 3 ;

require_once(' dbConnect.php');

$ total = mysqli_num_rows(mysqli_query($ con, 来自评估)的SELECT id);

$ page_limit = $ total / $ limit;

if($ page< = $ page_limit){

$ start =($ page - 1)* $ limit ;

$ sql = SELECT *来自评估的WHERE superHero ='。$ superHero。 'limit $ start,$ limit ;

$ result = mysqli_query($ con,$ sql);

$ res = array();

while($ row = mysqli_fetch_array($ result)){
array_push($ res,array(

username => $ row [' 用户名'],
rate => $ row [ ' rate'],
));
}
echo json_encode($ res);
} else {
echo 之上;
}







这是我的MainActivity

< pre lang =java> private JsonArrayRequest getDataFromServer( int requestCounts){


JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Config.DATA_URL + String .valueOf(requestCounts),
new Response.Listener< JSONArray>(){
@ Override
public void onResponse(JSONArray响应){
parseData(response);
}
},
new Response.ErrorListener(){
@ Override
public void onErrorResponse(VolleyError error){
// 如果发生错误,表示列表已到达
Toast.makeText(MainActivity。 没有更多可用项目,Toast.LENGTH_SHORT).show();
}
});

// 返回请求
return jsonArrayRequest;
}

private void getData(){
requestQueue.add(getDataFromServer(requestCount));
requestCount ++;
}


private void parseData(JSONArray数组){

for int i = 0 ; i< array.length(); i ++){

SuperHero superHero = SuperHero( );
JSONObject json = null;
尝试 {

json = array.getJSONObject(i);

superHero.setName(json.getString(Config.TAG_NAME));
superHero.setPublisher(json.getString(Config.TAG_PUBLISHER));

} catch (JSONException e){
e.printStackTrace();
}
listSuperHeroes.add(superHero);
}
adapter.notifyDataSetChanged();
}





和我的适配器类



  @覆盖 
public void onBindViewHolder(ViewHolder holder, int position){

SuperHero superHero = Data.get(position);

final String textx = superHero.getPublisher();
float ratingss = Float.parseFloat(textx);

holder.textViewName.setText(superHero.getName());
holder.textViewPublisher.setText(superHero.getPublisher());
holder.rate.setRating(ratingss);

}


@覆盖
public int getItemCount(){
return Data.size();
}

class ViewHolder extends RecyclerView.ViewHolder {

public TextView textViewName;
public TextView textViewPublisher;
public RatingBar rate;

public ViewHolder(查看itemView){
super (itemView );

textViewName =(TextView)itemView.findViewById(R.id.textViewName);
textViewPublisher =(TextView)itemView.findViewById(R.id.textViewPublisher);
rate =(ratingBar)itemView.findViewById(R.id.ratingBar);


}
}







谢谢提前帮忙! :D



我尝试了什么:



我添加了< pre lang =PHP> $ superHero = $ _GET [' superHero'];





  $ sql  =   SELECT *来自评估的WHERE superHero ='。$ superHero。 'ORDER BY id DESC limit $ start,$ limit; 





但坚持在代码中实现它。

解决方案

page =


_GET [' page'];


superHero =


I have been spending time learning RecyclerView and to display data into it. But I am faced with a problem and I wanted to consult with you guys on how to search in RecyclerView.

What I am intending to do is there will be a EditText and Button. When the app loads, there will be no data on the RecyclerView. But only when I type in the EditText on what to search for and then click the button. Then only will the app get the info from the database and show it in the RecyclerView.

Here is my php file

<?php 

$page = $_GET['page'];

    $superHero= $_GET['superHero'];

$start = 0; 

$limit = 3; 

    require_once('dbConnect.php');

    $total = mysqli_num_rows(mysqli_query($con, "SELECT id from evaluated"));

$page_limit = $total/$limit; 

if($page<=$page_limit){

    $start = ($page - 1) * $limit;

    $sql = "SELECT * from evaluated WHERE superHero='".$superHero."' limit $start, $limit";

    $result = mysqli_query($con,$sql); 

    $res = array(); 

    while($row = mysqli_fetch_array($result)){
        array_push($res, array(

            "username"=>$row['username'],
            "rate"=>$row['rate'],                
        ));
    }
    echo json_encode($res);
}else{
        echo "over";
}




And this is my MainActivity

private JsonArrayRequest getDataFromServer(int requestCounts) {


    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Config.DATA_URL + String.valueOf(requestCounts),
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    parseData(response);
                  }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    //If an error occurs that means end of the list has reached
                    Toast.makeText(MainActivity.this, "No More Items Available", Toast.LENGTH_SHORT).show();
                }
            });

    //Returning the request
    return jsonArrayRequest;
}

  private void getData() {
    requestQueue.add(getDataFromServer(requestCount));
   requestCount++;
   }  


private void parseData(JSONArray array) {

    for (int i = 0; i < array.length(); i++) {

        SuperHero superHero = new SuperHero();
        JSONObject json = null;
        try {

            json = array.getJSONObject(i);

            superHero.setName(json.getString(Config.TAG_NAME));
            superHero.setPublisher(json.getString(Config.TAG_PUBLISHER));

       } catch (JSONException e) {
            e.printStackTrace();
        }
        listSuperHeroes.add(superHero);
    }
    adapter.notifyDataSetChanged();
}



and my Adapter Class

@Override
public void onBindViewHolder(ViewHolder holder, int position) {

    SuperHero superHero =  Data.get(position);

    final String textx = superHero.getPublisher();
    float ratingss = Float.parseFloat(textx);

    holder.textViewName.setText(superHero.getName());
    holder.textViewPublisher.setText(superHero.getPublisher());
   holder.rate.setRating(ratingss);

}


@Override
public int getItemCount() {
    return Data.size();
}

class ViewHolder extends RecyclerView.ViewHolder{

    public TextView textViewName;
    public TextView textViewPublisher;
    public RatingBar rate;

    public ViewHolder(View itemView) {
        super(itemView);

        textViewName = (TextView) itemView.findViewById(R.id.textViewName);
        textViewPublisher = (TextView) itemView.findViewById(R.id.textViewPublisher);
       rate = (RatingBar) itemView.findViewById(R.id.ratingBar);


    }
}




Thanks in advance for any help! :D

What I have tried:

I have added

$superHero= $_GET['superHero'];


and

$sql = "SELECT * from evaluated WHERE superHero='".$superHero."' ORDER BY id DESC limit $start, $limit";



but stuck in implementing it in the code.

解决方案

page =


_GET['page'];


superHero=


这篇关于在recyclerview中显示特定信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆