当我尝试在列表视图中显示数据但数据不显示仅显示错误

时间:2014-05-08 09:44:37

标签: android list listview android-arrayadapter custom-adapter

我是新的ANdroid开发人员,我希望使用数组适配器在列表视图中显示数据,并且数据从数据库获取,这是Sqlite但数据未在A列表中显示仅查看False显示在一行中请任何人帮助我

我的主要活动代码在这里....

public class SmsMerge extends Activity  {
        private ImageButton btn;
        private ImageButton imgb;
        private TemplateOperation templateDBoperation;
        ArrayList<List> arr;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_sms_merge);
            templateDBoperation = new TemplateOperation(this);
            templateDBoperation.open();
            List values = templateDBoperation.getAllTemplate();
            arr=new ArrayList<List>();
               arr.add((ArrayList<List>)values);
            ListView listview = (ListView)findViewById(android.R.id.list);
    MyListAdapter adpttt=new MyListAdapter(SmsMerge.this,R.layout.row,arr);
            listview.setAdapter(adpttt);

    }
    }

我的自定义适配器代码在这里......

package com.example.sqliteapplication;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MyListAdapter extends ArrayAdapter<List> {
    List names;
    int inflatr;
    Context ctxt;
    ArrayList<List> data=new ArrayList<List>();
    public MyListAdapter(Context context, int layoutResourceId,
            ArrayList<List> data) {
        super(context, layoutResourceId, data);
        this.inflatr = layoutResourceId;
        this.ctxt = context;
        this.data= data;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        UserHolder holder = null;
         View row = convertView;
        if(convertView==null)
        {
             LayoutInflater inflater = ((Activity) ctxt).getLayoutInflater();
              row = inflater.inflate(inflatr, parent, false);
             holder = new UserHolder();
             holder.btnEdit = (ImageButton) row.findViewById(R.id.atomPay_removePay);
             row.setTag(holder);
        }
        else
        {
             holder = (UserHolder) row.getTag();            
        }
        List dta=data.get(position);
        holder.btnEdit.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                 Toast.makeText(ctxt, "Humayoon    Siddiqueeeeeeeeeeeeeeeeeee", Toast.LENGTH_SHORT).show();
            }
        });
        return row;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }


    static class UserHolder {
        TextView textName;
        TextView textAddress;
        TextView textLocation;
        ImageButton btnEdit;
        Button btnDelete;
        }



}

1 个答案:

答案 0 :(得分:0)

为什么使用列表类型的ArrayList ...如果从这里获取所有列表

List values = templateDBoperation.getAllTemplate();

然后将其传递给您的适配器。

试试这个。