2015-12-16 24 views
0

正在開發一個android應用程序。我的問題陳述如下:如何解析一個整數,它給出了android studio中的課程列表?

1)我需要在某些學院有ListView的課程可用。

2)我爲他們每個人的點(例如醫藥:30,數學24,英語:14,法國28,等...)

3)我需要解析點(整數)到相應的課程和更低的課程。

全樣本:

輸入您的要點:(比如說整數26)(EditText上) 後的人加入他的觀點,他得到的課程列表,他很可能在這樣的大學申請: 您有資格申請這些課程: 數學 英語(將以列表形式列出)

Ps正在使用android studio。 有人可以幫助我編程?感謝

mainactivity.java 


import android.os.Bundle; 
    import android.app.Activity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
    import android.widget.ArrayAdapter; 
    import android.widget.EditText; 
    import android.widget.ListView; 


    public class MainActivity extends Activity { 


    String[] courses = new String[]{ 

    "Mathematics", 
    "Chemical Engineering", 
    "Civil Engineering", 
    "Agriculture", 
    "Law and Management", 
    "Sociology", 
    "Information and Communication Technologies", 
    "Computer Science", 
    "Information Systems", 
    "Software Engineering", 


    }; 




    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.event2icon); 
    EditText editText = null; 
    editText=(EditText)findViewById(R.id.edit_text); 
    final String point=editText.getText().toString(); 
    final int point_integer=Integer.parseInt(point); 


    final ListView courselist = (ListView)findViewById(R.id.courseNames); 


    LayoutInflater inflater = getLayoutInflater(); 
    ViewGroup header = (ViewGroup)inflater.inflate(R.layout.listviewheader, courselist, false); 
    courselist.addHeaderView(header, null, false); 


    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, courses); 
    courselist.setAdapter(adapter); 
    courselist.setOnItemClickListener(new OnItemClickListener(){ 

    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int  position, long id) { 
     // TODO Auto-generated method stub 

     //we use the items of the listview as title of the next activity 
     if((Integer.parseInt(String.valueOf(point_integer))<=10)) 
     { 


     } 




    } 


    }); 

    } 
    } 




event2icon.xml 


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<EditText 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/edit_text" 
android:text="Enter your points:"/> 
<ListView 
android:id="@+id/courseNames" 
android:layout_width="match_parent" 
android:layout_below="@+id/edit_text" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:dividerHeight="15.0sp" 
    > 
    </ListView> 


</LinearLayout> 



listviewheader.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> 
+0

您能否使用您嘗試解決此問題的代碼更新您的問題? –

+2

[如何過濾Android中的對象列表]可能的重複(http://stackoverflow.com/questions/34271311/how-to-filter-a-list-of-objects-in-android) –

+0

歡迎使用Stack溢出。我們很樂意幫助你。爲了提高您獲得答案的機會,以下是一些提示:[我如何提出一個好問題?](http://stackoverflow.com/help/how-to-ask) – Soham

回答

0

你需要解析點成整數,然後通過傳遞整數查詢得到的合資格課程列表;從下面的代碼獲得point_integer並用它到你的查詢數據庫或ArrayList和設置aadapter到列表視圖對於與此相關的符合條件的課程列表

String point=edittext.getText().toString.trim(); 
int point_integer=Integer.parseInt(point); 
+0

先生,請幫助我糾正code.am我不能夠把每個課程的積分和迭代列表列表顯示列表使用listadapter – lovesh

+0

通過哪種情況你將定義,如果用戶有26分,那麼他有資格參加哪些課程? –