【问题标题】:How getting data from MySQL with Recycle view如何使用 Recyclerview 从 MySQL 获取数据
【发布时间】:2015-07-17 09:59:32
【问题描述】:

我正在尝试使用回收视图而不是列表视图从 mysql 获取数据,我已经看到如何从字符串数组创建回收视图,例如:

`String[] models = new String[]{"Gallardo", "Vyron", "Corvette", "Pagani Zonda", "Porsche 911 Carrera", "BMW 720i", "DB77", "Mustang", "Camaro", "CT6"};` 

但我不知道如何从 php 加载:

`{"db_evento":[{"id":"3","nome":"Almo\u00e7o na casa de isa","local":"Navegantes, valthier apto 301","valor":"0.00","categoria":"Familiar ","descricao":"Toda a fam\u00edlia"},{"id":"6","nome":"Above","local":"Chevrolet ","valor":"150.00","categoria":"Shows","descricao":"Above and beyond no Chevrolet hall, as 22h dia 05\/06\/2014"},{"id":"7","nome":"Passeio de catamaram ","local":"Porto","valor":"15.00","categoria":"Passeio ","descricao":"Passeio de catamaram por recife "},{"id":"8","nome":"Corrida","local":"Ca\u00e7ad\u00e3o boa viagem ","valor":"0.00","categoria":"Passeio ","descricao":"Corrida de Cooper no calcadao de boa viagem as 7h"}],"success":1}`

或来自json之类的:

``{"orders":[
            {"id":"681","item":"Pizza"},
            {"id":"690","item":"Pasta"},
            {"id":"701","item":"Coke"},
            {"id":"710","item":"Burger"},
            {"id":"720","item":"Finger-Chips"},
            {"id":"730","item":"Noodles"}
            ],``

【问题讨论】:

标签: php android mysql sql json


【解决方案1】:

你的问题的标题与你的问题的发展不同。 如果您需要使用来自 MySql 的数据填充回收视图,则需要向适配器添加一些额外的代码。其实很简单。我正在输入一些 sn-p 让你继续前进。希望对您有所帮助。

class MyAdapter extends  RecyclerView.Adapter<RecyclerView.ViewHolder> {

private Context context;    
private Cursor cursor; // Your data
public MyAdapter( Context context, Cursor cursor) {
  this.context = context;
  this.cursor = cursor;
}

 public Cursor swapCursor(Cursor cursor) {
    if (this.cursor == cursor) {
        return null;
    }
    Cursor oldCursor = this.cursor;
    this.cursor = cursor;
    if (cursor != null) {
        this.notifyDataSetChanged();
    }
    return oldCursor;
}
public void changeCursor(Cursor cursor) {
    Cursor old = swapCursor(cursor);
    if (old != null) {
        old.close();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多