0
我想開發一個android手機應用程序,我需要顯示一部分至少有100個項目的列表視圖。 現在我作爲一所大學的管理人員,列出了100門課程(所有課程都列在listview中)。所有課程都有一個要點,並且爲了讓申請人申請此課程,他/她需要有準確的高points.An的指示樣品低於: 英語:24 西班牙:16個 數學:28 科學:26 法國:16 管理:22 法:30 亞洲語言:10如何根據用戶的不同要求只選擇部分列表視圖?
現在,學生需要輸入他/她的觀點,並根據(確切或較低點),他/她得到他/她有資格申請的科目清單
例如,輸入您的積分:24
輸出在ListView應給出如下: 法國:16 管理:22 英語:24 亞洲語言:10
我試過,但我堅持和無法完成代碼:
Course.java
public class Course {
private String name;
private int points;
public Course(String name, int points) {
this.name = name;
this.points = points;
}
public String getName() {
return name;
}
public int getPoints() {
return points;
}
@Override
public String toString() {
return getName();
}
}
Course[] courses = new Course[]{
new Course("Medicine", 30),
new Course("Physics", 28),
new Course("Math", 24),
new Course("English", 20)
};
Button searchButton = (Button) findViewById(R.id.btn_search);
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<Course> courseList = new ArrayList<Course>(Arrays.asList(courses));
// initialize the adapter with courseList... //
// this code inside the Button's onClick
int points = Integer.parseInt(editText.getText().toString());
for (Course c : courses) {
if (c.getPoints() <= points) {
adapter.add(c);
}
}
course.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:maxLines="1"
android:inputType="number"
android:layout_height="wrap_content"
android:hint="Enter your points:"
android:id="@+id/editText"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:id="@+id/btn_search"/>
</LinearLayout>
<ListView
android:id="@+id/courseNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>