0

我有一个从数据库中检索到的列表视图

 public class DiseaseList extends ListActivity{


DataHelper dh;



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

    dh = new DataHelper(this);
    dh.open();
    dh.getAllDiseaseNames();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);

    setListAdapter(adapter);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    String item=(String)getListAdapter().getItem(position);


    if(item.equals("Pain")){
        dh.getSymptomsByDiseaseId(1);   
        startActivity(new Intent(DiseaseList.this,Symptoms.class));
            }
            else if(item.equals("Color change in teeth")){
                dh.getSymptomsByDiseaseId(2);
                startActivity(new Intent(DiseaseList.this,Symptoms.class));
            }
            else if(item.equals("bleeding gums")){
                startActivity(new Intent(DiseaseList.this,Questions.class));
            }
            else if(item.equals("decay in teeth")){
                startActivity(new Intent(DiseaseList.this,Questions.class));
            }
            else if(item.equals("dislodged caps")){
                startActivity(new Intent(DiseaseList.this,Questions.class));
            }
            }
              }

我的 datahelper 类方法来检索这些数据是:

 public List<String> getAllDiseaseNames() {
         List<String> diseasename = null;

         cr = db.query(DISEASE_TABLE_NAME,new String[] {DISEASE_NAME}, null, null, null, null, null);

            if(null != cr){
                  diseasename = new ArrayList<String>();
                  if (cr.moveToFirst()) {
                     do {
                        diseasename.add(cr.getString(0));
                     }  while (cr.moveToNext());
                  }

                  if (cr != null && !cr.isClosed()) {
                      cr.close();
                  }
              }
              return diseasename;
           } 


     //symptomsbydiseaseid to get symptoms in list view

     public List<String> getSymptomsByDiseaseId(long diseaseId) {

            List<String> symptomsList = new ArrayList<String>();

            String selection = "diseaseid=?";
            String[] selectionArgs = { String.valueOf(diseaseId) };
            cr = db.query(false, SYMPTOM_TABLE_NAME, null, selection, selectionArgs, null, null, null, null);
            if (cr.moveToFirst()) {
                do {
                    symptomsList.add(cr.getString(0));
                } while (cr.moveToNext());
            }
            cr.close();

            return symptomsList;
        }

现在在第一个列表视图中,当我单击 "A" 时,我应该移动到另一个列表活动并在类别 A 下显示另一个列表视图,与 B、C 和 D 相同......在另一个列表视图下,它将有另一个列表单击它们时要问的问题

我的症状如下:

package com.dentabtechnologies.appstart;

import com.example.dentabtechnologies.R;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Symptoms extends ListActivity {

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

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);

    setListAdapter(adapter);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
}   

} 

我怎样才能做到这一点?谢谢

流程来自疾病列表视图>症状列表视图>子症状列表视图>和不同文本视图中的问题

4

1 回答 1

0

首先向适配器添加数据:

adapter.addAll(dh.getAllDiseaseNames())
于 2013-07-18T07:02:34.457 回答