关于bmob的listview问题,求大神看看我哪里错了!

主MainActivity代码

 import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;


public class MainActivity extends Activity {


    private ListView mlistView;
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.activity_main);
     // 初始化 Bmob SDK
        // 使用时请将第二个参数Application ID替换成你在Bmob服务器端创建的Application ID
        Bmob.initialize(this, "Application ID");


        setTitle("查询信息");
        mlistView = (ListView)findViewById(R.layout.activity_main);

        openlistview();

    }


    public void openlistview(){

        BmobQuery<ZhinengBean> query = new BmobQuery<ZhinengBean>();
        query.order("-createdAt");
        query.findObjects(this, new FindListener<ZhinengBean>() {
                @Override
                public void onSuccess(List<ZhinengBean> mList) {
                    // TODO Auto-generated method stub


                        if (mList == null || mList.size() == 0) {
                            myAdapter.onDateChange(mList);
                            Toast.makeText(MainActivity.this,"适配器失败", Toast.LENGTH_LONG).show();


                        }


                        //这里应该是要解析,我不太懂怎么解析
                        //Bmob服务器的JavaBean是有数据的。
                        myAdapter = new MyAdapter(MainActivity.this, mList);
                        mlistView = (ListView)findViewById(R.layout.activity_main);
                        mlistView.setAdapter(myAdapter);

                        Toast.makeText(MainActivity.this,"查询成功"+mList, Toast.LENGTH_LONG).show();

                }


                @Override
                public void onError(int code, String zhinengBeans) {
                    // TODO Auto-generated method stub
                    Toast.makeText(MainActivity.this,"查询失败。", Toast.LENGTH_LONG).show();

                }
        });

    }




}

主布局代码listview
activity_main

```<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"

android:orientation="horizontal" >

<ListView
    android:id="@+id/lv_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />



内容代码
item_layout

<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:orientation="horizontal" >

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:paddingLeft="4dp">



    <TextView 
        android:id="@+id/tv_tittle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:textSize="15sp"
        android:text="Tittle"/>    
        //maxLines最多多少行
    <TextView 
        android:id="@+id/tv_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="3"
        android:textSize="10sp"
        android:text="Content"/>

</LinearLayout>






BaseAdapter代码 //我觉得应该没啥问题这里

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {

//通过构造方法,将数据源和适配器绑定在一起》》》》
private Context Context;
private List<ZhinengBean> mList;
private LayoutInflater mInflater;
public MyAdapter (
        Context context,
        List<ZhinengBean> list){

    this.Context = context;


    this.mList = list;
    mInflater = LayoutInflater.from(context);
}
//》》》》》》》

public void onDateChange(List<ZhinengBean> mList) {
    this.mList = mList;
    this.notifyDataSetChanged();


}


//表示显示多少条数据
@Override
public int getCount() {
    // TODO 自动生成的方法存根
    return  mList.size();
}

@Override
public Object getItem(int position) {
    // TODO 自动生成的方法存根
    return mList.get(position);
}

@Override
public long getItemId(int position) {
    // TODO 自动生成的方法存根
    return position;
}

@Override
public View getView(int position, View converView, ViewGroup parent) {
    // TODO 自动生成的方法存根
    ViewHolder viewHolder = null;
    if(converView == null){
        viewHolder = new ViewHolder();
        converView = mInflater.inflate(R.layout.iten_layout,null);

        viewHolder.znTittle = (TextView) converView.findViewById(R.id.tv_tittle);
        viewHolder.znTittle2 = (TextView) converView.findViewById(R.id.tv_content);
        converView.setTag(viewHolder);
    }else{
        viewHolder = (ViewHolder) converView.getTag();
    }
    ZhinengBean td =mList.get(position);  //新方法

    viewHolder.znTittle.setText(td.getZntittle());
    viewHolder.znTittle2.setText(td.getZntittle2());

    return converView;
}

class ViewHolder {

public TextView znTittle;
public TextView znTittle2;

3个回答

是不是Bmob云端得Javascript写错了?

ZhinengBean 可能是这个问题, 类名称和表名不一致,就会查不出数据。

去官网的问答社区提问啊,效率挺高的Bmob问答社区

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐