1

我已经创建了一个带有标题的列表视图,但我无法对同一标题下的项目进行分组。

有人可以建议我该怎么做吗?

以下是将项目显示到列表视图中的代码:

public class OrganizationList extends Activity implements OnClickListener {

    ListView lv;
    SimpleAdapter simpleAdapter;
    ArrayList<HashMap<String, String>> videosList;

    // Progress Dialog
    private ProgressDialog pDialog;

    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();
    JSONArray videos = null;

    // url to get all videos
    private static String url_video = "http://10.0.2.2/android_connect/get_organization.php";

    //JSON Nodes
    private static final String TAG_POSITION = "position";
    private static final String TAG_URL = "URL";
    private static final String TAG_MEMBER = "name";
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_NAME = "members";
    protected static final int GET_INTENT_CODE = 0;


     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.video);

            Button refresh = (Button)findViewById(R.id.btn_refresh);
            refresh.setOnClickListener(this);

            TextView header = (TextView)findViewById(R.id.text_header);
            header.setText("Videos (视频)");

            ImageButton home = (ImageButton)findViewById(R.id.btn_home);
            home.setOnClickListener(this);

            // Hashmap for ListView
            videosList = new ArrayList<HashMap<String, String>>();

            //Get adapter
            simpleAdapter = new SimpleAdapter(OrganizationList.this, videosList, R.layout.list_date_item, new String[] {TAG_POSITION, TAG_MEMBER},
                    new int[] { R.id.text_header, R.id.name});

            //Get Listview
            lv = (ListView) findViewById(R.id.lst_name);
            lv.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // getting values from selected ListItem

                    String videoName = ((TextView) view.findViewById(R.id.name)).getText()
                    .toString();
                    Log.d("row click:", videoName);

                }
            });

            // Loading videos in Background Thread
            new LoadAllVideos().execute();
     }

     /**
         * Background Async Task to Load all product by making HTTP Request
         * */
        class LoadAllVideos extends AsyncTask<String, String, String> {

            /**
             * Before starting background thread Show Progress Dialog
             * */
             @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(OrganizationList.this);
                pDialog.setMessage("Loading" + "\n" + "Please wait...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();
            } 

            /**
             * getting All videos from url
             * */
            protected String doInBackground(String... args) {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                // getting JSON string from URL
                JSONObject json = jParser.makeHttpRequest(url_video, "GET", params);

                // Check your log cat for JSON reponse
                Log.d("All videos: ", json.toString());

                try {
                    // Checking for SUCCESS TAG
                    int success = json.getInt(TAG_SUCCESS);

                    if (success == 1) {
                        // videos found
                        // Getting Array of videos
                        videos = json.getJSONArray(TAG_NAME);

                        // looping through All videos
                        for (int i = 0; i < videos.length(); i++) {
                            JSONObject c = videos.getJSONObject(i);

                            // Storing each json item in variable
                            String post = c.getString(TAG_POSITION);
                            String name = c.getString(TAG_MEMBER);
                            //videosList.add(c.getString(TAG_COMPANY));

                            //Log.d("item Name:", name);
                            //Log.d("companyNAme", videosList.get(0));

                            // creating new HashMap
                            HashMap<String, String> map = new HashMap<String, String>();

                            // adding each child node to HashMap key => value
                            map.put(TAG_POSITION, post);
                            map.put(TAG_MEMBER, name);

                            // adding HashList to ArrayList
                            videosList.add(map); 

                            //System.out.println(map);                  
                        }           

                    } 
                    else {

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                return null;
            }


        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all videos
            pDialog.dismiss();

            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */ 

                       // ListView Adapter

                    lv = (ListView) findViewById(R.id.lst_name);
                    lv.setAdapter(simpleAdapter);
                }
            });


        }
        }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v.getId() == R.id.btn_refresh)
        {
            videosList.clear();
            new LoadAllVideos().execute();
        }
        else if(v.getId() == R.id.btn_home)
        {

            Intent intent = new Intent();
            intent.setClassName("com.scba", "com.scba.Menu");
            finish();

        }
    }
}

截屏:

在此处输入图像描述

4

1 回答 1

0

只需更改您的 itemxml 文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/grayimage"
>

<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="president"
android:id="@+id/headerText"
/>

</FrameLayout>

<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Prof. Dr. Khanuka"
android:id="@+id/DiscriptionText"
/>

</LinearLayout>

然后从这里自定义列表创建您的客户列表

并根据您编辑您的代码

谢谢

于 2012-11-19T07:51:11.650 回答