有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

带列表的java SQLite

我有一个包含列表的活动。此列表将从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);

}
   }

这就是课堂

 public class RecentCaseClass {

private String pic;
private String name;
private String gender;
private int age;
private String clothes;
private String MoreInfo;
private String time;
private String location;
private int ID;

public String getPic() {
    return pic;
}

public void setPic(String pic) {
    this.pic = pic;
}
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getGender() {
    return gender;
}

public void setGender(String gender) {
    this.gender = gender;
}

public int getAge() {
    return age;
}

public void setAge(int age) {
    this.age = age;
}

public String getClothes() {
    return clothes;
}

public void setClothes(String clothes) {
    this.clothes = clothes;
}

public String getMoreInfo() {
    return MoreInfo;
}

public void setMoreInfo(String moreInfo) {
    MoreInfo = moreInfo;
}

public String getTime() {
    return time;
}

public void setTime(String time) {
    this.time = time;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public int getID() {
    return ID;
}

public void setID(int iD) {
    ID = iD;
}

  }

短信会出现在我的应用程序中,然后我会保存在SQLite中,然后我会在我的应用程序中显示它

  1. 如何从SQLite获取数据并在列表中显示
  2. 如果我从SQLite中删除行信息,如何删除列表中的行
  3. 我应该换适配器吗

===========================================更新===========================

我把这个添加到我的项目中,但我没有改变任何东西,只是添加了这个类:

        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);
        }


    }

}

共 (0) 个答案