Java 带列表的SQLite

Java 带列表的SQLite,java,android,sqlite,list,Java,Android,Sqlite,List,我有一个包含列表的活动。此列表将从SQLite获取数据: public class RecentCases extends Activity { Button GoToCaseInfo, CreateNewFormB; RecentCaseClass recent1; // the adapter class.. class RecentCasesInfoAdapter extends ArrayAdapter<RecentCaseClass> {

我有一个包含列表的活动。此列表将从SQLite获取数据:

public class RecentCases extends Activity {

Button GoToCaseInfo, CreateNewFormB;
RecentCaseClass recent1;

        // the adapter class..
    class RecentCasesInfoAdapter extends ArrayAdapter<RecentCaseClass>

   {
    public RecentCasesInfoAdapter() {

        super(RecentCases.this, R.layout.recent_cases_row);
    }

    public View getView(final int position, View convertView,
            ViewGroup parent)

    {

        recent1 = this.getItem(position);

        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.recent_cases_row, parent,
                false);
        // this is our row items..
        TextView recentName = (TextView) row
                .findViewById(R.id.tvrecentName);
        TextView recenInfo = (TextView) row.findViewById(R.id.recent_info);
        ImageView recentImg = (ImageView) row.findViewById(R.id.list_image);

        // TODO What's the info they want
        // String CaseTime = recent1.getTime();
        // recentName.setText(recent1.getName());
        // recenInfo.setText("His/her age: " + recent1.getAge() +
        // " year old"
        // + " Lost sicnce :" + CaseTime);

        String CasePicPath;

        // TODO Linear or ??
        RelativeLayout rowLayout = (RelativeLayout) row.findViewById(R.id.row_layout);
        rowLayout.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            // go to 
            Intent k = new Intent(RecentCases.this, Case_Information.class);
            startActivity(k);
        }
    });

        return row;

    }
    }

        protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recent_cases);

    // Moving to Create New Form Activity
    CreateNewFormB = (Button) findViewById(R.id.cretnwfrmRC);
    CreateNewFormB.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            Intent k = new Intent(RecentCases.this, CreateNewForm.class);
            startActivity(k);

        }
    });

    // For list
    // Intilaize
    ListView RecentCasesListView = (ListView)     findViewById(R.id.recent_cases_list);

    // create adapter
    RecentCasesInfoAdapter recentCasesInfoAdapter = new    RecentCasesInfoAdapter();

    // 1-First receives MMS OnReceive Class 2- Assign the MMS info to Static
    // Array 3- Assign the array to the adapater
    // for(MedicineClass m: Model.getMedList()) MedicineInfoAdapter.add(new
    // MedicineClass(m));
    recentCasesInfoAdapter.add(recent1);

    // after fill the adapter.. assign the list to the adapter
     RecentCasesListView.setAdapter(recentCasesInfoAdapter);

}
   }
短信将来到我的应用程序,然后我将保存在SQLite中,然后我应该在我的应用程序中显示它

  • 如何从SQLite获取数据并将其显示在列表中
  • 如果我从SQLite中删除行信息,如何删除列表中的行
  • 我应该换适配器吗 ========================================更新===========================

    我将此添加到我的项目中,但我没有更改任何内容,只是添加了此类:

            public class RecentClassAdapter extends BaseAdapter{
    
    
            private RecentCases RecentCases;
            static public List<RecentCaseClass> listOfRCases;
            RecentCaseClass entry;
            int caseId;
    
            public RecentClassAdapter(RecentCases recentcases, List<RecentCaseClass> listOfCaseParameter) {
                this.RecentCases = recentcases;
                this.listOfRCases = listOfCaseParameter;
    
            }
    
            public int getCount() {
                return listOfRCases.size();
            }
    
            public Object getItem(int position) {
                return listOfRCases.get(position);
            }
    
            public long getItemId(int position) {
                return position;
            }
    
            public View getView(int position, View convertView, ViewGroup viewGroup) {
    
                 entry = listOfRCases.get(position);
                 caseId = entry.getID();
    
                 if (convertView == null) {
    
                    LayoutInflater inflater = (LayoutInflater) RecentCases.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    convertView = inflater.inflate(R.layout.recent_cases_row, null);
                  }
    
                // this is row items..
                // Set the onClick Listener on this button
                 //ConfExpandRegion = (Button) convertView.findViewById(R.id.expand);
                //Button Cancelb = (Button) convertView.findViewById(R.id.cancelCase);
                TextView RCase = (TextView) convertView.findViewById(R.id.tvrecentName);
                RCase.setText(entry.getName());
                Toast.makeText(RecentCases, "inside getview" + entry.getAge(), 0).show(); 
    
            public void add(RecentCaseClass RCaseClass) {
                // TODO Auto-generated method stub
                listOfRCases.add(RCaseClass);
            }
    
    
        }
    
    }
    
    公共类RecentClassAdapter扩展了BaseAdapter{
    私人最近案件最近案件;
    静态公开列表案例;
    最近的案件类别记录;
    内酪蛋白;
    公共RecentClassAdapter(RecentCases RecentCases,CaseParameter列表){
    this.RecentCases=RecentCases;
    this.listOfRCases=listofCase参数;
    }
    public int getCount(){
    返回listofCases.size();
    }
    公共对象getItem(int位置){
    返回listofCases.get(位置);
    }
    公共长getItemId(int位置){
    返回位置;
    }
    公共视图getView(int位置、视图转换视图、视图组视图组){
    entry=listofcases.get(位置);
    caseId=entry.getID();
    if(convertView==null){
    LayoutInflater充气器=(LayoutInflater)RecentCases.getSystemService(Context.LAYOUT\u充气器\u服务);
    convertView=充气机。充气(R.layout.recent\u cases\u row,空);
    }
    //这是行项目。。
    //在此按钮上设置onClick侦听器
    //ConfExpandRegion=(按钮)convertView.findViewById(R.id.expand);
    //Button Cancelb=(Button)convertView.findViewById(R.id.cancelCase);
    TextView RCase=(TextView)convertView.findViewById(R.id.tvrecentName);
    RCase.setText(entry.getName());
    Toast.makeText(最近的案例,“内部getview”+entry.getAge(),0.show();
    公共无效添加(RecentCaseClass){
    //TODO自动生成的方法存根
    listofCases.add(RCaseClass);
    }
    }
    }
    
    您必须创建一个自定义数组适配器,逐行从数据库中获取数据,并使用getView方法填充Listview

    下面是一个自定义阵列适配器的示例


    如果您想将sqlite与列表绑定,在您的情况下,最好使用游标适配器。因此,我应该更改我的适配器?是的。游标适配器将观察您的列表数据。您能告诉我还应该更改什么吗?或者它只是适配器代码?您应该扩展游标适配器,而不是ArrayAdapter。在onCreate方法中调用query并设置适配器startManagingCursor(cursor);YourAdapter=新的YourAdapter(这个,光标);setListAdapter(适配器);不,您可以再做一件事,获取arraylist中的所有数据,并使用适配器将这些数据填充到listview中。
            public class RecentClassAdapter extends BaseAdapter{
    
    
            private RecentCases RecentCases;
            static public List<RecentCaseClass> listOfRCases;
            RecentCaseClass entry;
            int caseId;
    
            public RecentClassAdapter(RecentCases recentcases, List<RecentCaseClass> listOfCaseParameter) {
                this.RecentCases = recentcases;
                this.listOfRCases = listOfCaseParameter;
    
            }
    
            public int getCount() {
                return listOfRCases.size();
            }
    
            public Object getItem(int position) {
                return listOfRCases.get(position);
            }
    
            public long getItemId(int position) {
                return position;
            }
    
            public View getView(int position, View convertView, ViewGroup viewGroup) {
    
                 entry = listOfRCases.get(position);
                 caseId = entry.getID();
    
                 if (convertView == null) {
    
                    LayoutInflater inflater = (LayoutInflater) RecentCases.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    convertView = inflater.inflate(R.layout.recent_cases_row, null);
                  }
    
                // this is row items..
                // Set the onClick Listener on this button
                 //ConfExpandRegion = (Button) convertView.findViewById(R.id.expand);
                //Button Cancelb = (Button) convertView.findViewById(R.id.cancelCase);
                TextView RCase = (TextView) convertView.findViewById(R.id.tvrecentName);
                RCase.setText(entry.getName());
                Toast.makeText(RecentCases, "inside getview" + entry.getAge(), 0).show(); 
    
            public void add(RecentCaseClass RCaseClass) {
                // TODO Auto-generated method stub
                listOfRCases.add(RCaseClass);
            }
    
    
        }
    
    }