设置响应的ListView [英] Setting response to listView

查看:99
本文介绍了设置响应的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已得到服务器,我已经存储在list.I我得到了整个DATAIN list.But我希望它设置为从列表中的数据设置为两个不同的textViews.How我能干这事响应已经解析数据,得到了恰当的反应,但只是想将数据分成两个textViews

我的code是

  myList中=新的ArrayList<&HashMap的LT;弦乐,对象>>();             mainListView =(ListView控件)findViewById(R.id.main_listview);                    / * TV =(的TextView)findViewById(R.id.result);
            TV1 =(的TextView)findViewById(R.id.result1);
            TV2 =(的TextView)findViewById(R.id.result2); * /
            请求=新SoapObject空间(namespace,METHOD_NAME);
            request.addProperty(FilterCondition中,);
            request.addProperty(用户ID,-1);
            request.addProperty(类型,ALL);
            request.addProperty(PAGEID,1);
            request.addProperty(SITEURL,http://www.xxx.mobi/);
            request.addProperty(SortCondition,按名称顺序);
            request.addProperty(FilterID,-1);
            request.addProperty(KEYVALUE,1);
            request.addProperty(EventFilterType,);
            SoapSerializationEnvelope信封=新SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = TRUE;
            SoapObject结果= NULL;
            envelope.setOutputSoapObject(请求);
            AndroidHttpTransport SAB =新AndroidHttpTransport(URL);
            // C类=新类别();
            sab.debug = TRUE;
            尝试{
                sab.call(SOAP_ACTION,信封);
                如果(envelope.getResponse()!= NULL){
                    结果=(SoapObject)envelope.bodyIn;
                    的String []值=新的String [result.getPropertyCount()];
                    的for(int i = 0; I< result.getPropertyCount();我++){
                        Log.d(值,result.getProperty(ⅰ)的ToString());
                        INT J = result.getPropertyCount();
                        Log.d(计数,Integer.toString(J));
                    // tv.setText(SS:+结果);
                        Log.d(地位,result.toString());
                    }
                    名单=新的ArrayList<串GT;(
                            result.getPropertyCount());
                    字符串lv_arr [] =新的String [result.getPropertyCount()];
                    为(中间体I1 = 0; I1&所述; 1;的i1 ++){
                        对象属性= result.getProperty(I1);
                        如果(财产的instanceof SoapObject)
                        {
                            SoapObject countryObj =(SoapObject)财产;
                            SoapObject国家名称=(SoapObject)countryObj
                                    .getProperty(的DiffGram);
                            SoapObject国家=(SoapObject)国家名称
                                    .getProperty(NewDataSet);
                            SoapObject SS =(SoapObject)国家
                                    .getProperty(表);
                            Log.d(消息,ss.getProperty(姓名)的toString());
                            list.add(ss.getProperty(姓名)的toString());
                            list.add(ss.getProperty(SHORTDESCRIPTION)的toString());
                            list.add(ss.getProperty(IconPath)的toString());                            Log.d(列表值,list.toString());                            / *
                             * JSONObject的O =新的JSONObject(SR); JSONArray
                             * JS = o.getJSONArray(表);为(中间体I4 = 0; 6-14&下;
                             * js.length(); 6-14 ++){
                             *
                             * Log.d(log_tag,_ ID+ o.getInt(姓名)+
                             *,mall_name+ o.getString(对象ID)+
                             *,地点+ o.getString(的ComponentID));
                             * /
                            /*tv.setText(list.get(0)的ToString());
                            tv1.setText(list.get(1)的ToString());
                            tv2.setText(list.get(2)的ToString()); * /                        }                        其他
                        {
                            Log.d(响应,空);
                        }
                    }
                // addDataToList();
                    ArrayList的fillMaps =新的ArrayList();
                            对(INT I = 0; I&小于10;我++){
                                 HashMap的<弦乐,对象> MAP1 =新的HashMap<弦乐,对象>();
                            map1.put(图标,R.drawable.ic_launcher);
                            map1.put(教程,清单);
                            map1.put(描述,);
                              fillMaps.add(MAP1);
                            }                    SimpleAdapter AA =新SimpleAdapter(这一点,fillMaps,R.layout.row,
                            新的String [] {课程,说明,图标},
                            新的INT [] {R.id.txt1,R.id.txt2,R.id.img1});
                            mainListView.setAdapter(AA);
                }
            }
            赶上(例外五){
                e.printStackTrace();
            }


解决方案

你需要定制的ListView? (意思是你想显示每行两个文本框?)

I have got the response from server which I have stored in the list.I am getting the whole datain list.But I want it to set to set the data from list to two different textViews.How can I do this.I have already parse the data and got the proper response but just want to split data into two textViews

My Code is

myList = new ArrayList<HashMap<String, Object>>();

             mainListView = (ListView) findViewById(R.id.main_listview);



                    /*tv = (TextView) findViewById(R.id.result);
            tv1 = (TextView) findViewById(R.id.result1);
            tv2 = (TextView) findViewById(R.id.result2);*/
            request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("FilterCondition", "");
            request.addProperty("UserID", -1);
            request.addProperty("Type", "ALL");
            request.addProperty("PageID", 1);
            request.addProperty("SiteURL", "http://www.xxx.mobi/");
            request.addProperty("SortCondition", "order by name");
            request.addProperty("FilterID", -1);
            request.addProperty("KeyValue", 1);
            request.addProperty("EventFilterType", "");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            SoapObject result = null;
            envelope.setOutputSoapObject(request);
            AndroidHttpTransport sab = new AndroidHttpTransport(URL);
            // Category C=new Category();
            sab.debug = true;
            try {
                sab.call(SOAP_ACTION, envelope);
                if (envelope.getResponse() != null) {
                    result = (SoapObject) envelope.bodyIn;
                    String[] values = new String[result.getPropertyCount()];
                    for (int i = 0; i < result.getPropertyCount(); i++) {
                        Log.d("Value", result.getProperty(i).toString());
                        int j = result.getPropertyCount();
                        Log.d("count is", Integer.toString(j));
                    //  tv.setText("ss:" + result);
                        Log.d("status", result.toString());
                    }
                    list = new ArrayList<String>(
                            result.getPropertyCount());
                    String lv_arr[] = new String[result.getPropertyCount()];
                    for (int i1 = 0; i1 < 1; i1++) {
                        Object property = result.getProperty(i1);
                        if (property instanceof SoapObject) 
                        {
                            SoapObject countryObj = (SoapObject) property;
                            SoapObject countryName = (SoapObject) countryObj
                                    .getProperty("diffgram");
                            SoapObject country = (SoapObject) countryName
                                    .getProperty("NewDataSet");
                            SoapObject ss = (SoapObject) country
                                    .getProperty("Table");
                            Log.d("message", ss.getProperty("Name").toString());
                            list.add(ss.getProperty("Name").toString());
                            list.add(ss.getProperty("ShortDescription").toString());
                            list.add(ss.getProperty("IconPath").toString());

                            Log.d("list values", list.toString());

                            /*
                             * JSONObject o = new JSONObject(sr); JSONArray
                             * js=o.getJSONArray("Table"); for(int i4 = 0; i4 <
                             * js.length(); i4++){
                             * 
                             * Log.d("log_tag","_id"+o.getInt("Name")+
                             * ", mall_name"+o.getString("ObjectID")+
                             * ", location"+o.getString("ComponentID"));
                             */
                            /*tv.setText(list.get(0).toString());
                            tv1.setText(list.get(1).toString());
                            tv2.setText(list.get(2).toString());*/

                        }

                        else 
                        {
                            Log.d("response", "null");
                        }
                    }


                //  addDataToList();
                    ArrayList fillMaps = new ArrayList();  
                            for(int i = 0; i < 10; i++){
                                 HashMap<String,Object > map1 = new HashMap<String,Object>();
                            map1.put("icon", R.drawable.ic_launcher);
                            map1.put("Course", list);
                            map1.put("Description", "");
                              fillMaps.add(map1);
                            }

                    SimpleAdapter aa = new SimpleAdapter(this, fillMaps, R.layout.row,
                            new String[] {"Course", "Description", "icon"}, 
                            new int[] {R.id.txt1, R.id.txt2, R.id.img1});
                            mainListView.setAdapter(aa);
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }

解决方案

Do you need customized listView ? (mean you want to display 2 text boxes per row ?)

这篇关于设置响应的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆