2

ここで私はコーディングしたいです。

女の子に支払う = 100 100 の値 (100 はブラウザの XML ファイルからの値) = 色は赤

女の子に支払う = 200 200 の値 (200 はブラウザの XML ファイルからの値) = 緑の色

少年に支払う = 100 100 の値 (100 はブラウザの XML ファイルからの値) = 色は赤

少年に支払う = 200 200 の値 (200 はブラウザの XML ファイルからの値) = 色は緑色

200 のようなブラウザーの XML ファイルからのより高い値の場合、リスト ビューの 200 の色は緑であり、ブラウザーの XML ファイルからの 100 のようなより低い値は、リスト ビューの 100 の色は赤です。変更される値は、ブラウザーの XML ファイルによって異なります。私はDOMパーサーを使用して、少年に支払う価値と少女に支払う価値を取得しています。また、タイマーを使用して数秒で自動更新しています。タイマーを使用したコード XML 解析で、色を変更するように要求するコードを配置するにはどうすればよいですか? 私はその中で何かをしますが、失敗しました。

ここにコードがあります

@Override
         public void onResume() {
          super.onResume();
          Timer autoUpdate = new Timer();
          autoUpdate.schedule(new TimerTask() {
           @Override
           public void run() {
            runOnUiThread(new Runnable() {
             public void run() {
                 ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

                 quotesXMLParsing parser = new quotesXMLParsing();
                String xml = parser.getXmlFromUrl(URL); // getting XML
                Document doc = parser.getDomElement(xml); // getting DOM element

                NodeList nl = doc.getElementsByTagName(KEY_item);
                // looping through all item nodes <item>
                for (int i = 0; i < nl.getLength(); i++) {
                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();
                    Element e = (Element) nl.item(i);
                    // adding each child node to HashMap key => value
                    map.put(KEY_price, parser.getValue(e, KEY_price));
                    map.put(KEY_pay of the girl, parser.getValue(e, KEY_pay of the girl));
                    map.put(KEY_pay of the boy,  parser.getValue(e, KEY_pay of the boy));


                    // adding HashList to ArrayList
                    menuItems.add(map);
                }

                // Adding menuItems to ListView
                ListAdapter adapter = new SimpleAdapter(Activity.this, menuItems,
                        R.layout.showquotes,
                        new String[] { KEY_price, KEY_pay of the girl, KEY_pay ogf the boy }, new int[] {
                                R.id.price, R.id.pay of the girl, R.id.pay of the boy });

                setListAdapter(adapter);
             }
            });
           }
          }, 0, 5000); 
         }
}

ここにXMLファイルがあります

<items>
<item>
<price>100</price>
<pay of the girl>100</pay of the girl>
<pay of the boy>200</pay of the boy>
</item>

100 や 200 などの値は 5 秒ごとに変化します

ここでコードを試しましたが、失敗しました。

ListAdapter adapter = new SimpleAdapter(Activity.this, menuItems,
                        R.layout.showquotes,
                        new String[] { KEY_price, KEY_pay of the girl, KEY_pay ogf the boy }, new int[] {
                                R.id.price, R.id.pay of the girl, R.id.pay of the boy });               


            ListAdapter.setViewBinder(new MyViewBinder1());           
            itemlist.setAdapter(ListAdapter);



 class MyViewBinder1 implements ViewBinder 
 {      @Override
            public boolean setViewValue(View view, Object Status,String textRepresentation)
            {       
                  String complet="Pay of the girl:+higher ";
                  String complet1="Pay of the boy:+higher";
          String notcomplet="Pay of the girl:-lower";
                  String notcomlet="Pay of the boy:-lower";


                  String getdata= textRepresentation;


                    if((view instanceof TextView) & (Status instanceof String) )
                    { 
                            TextView iv= (TextView) view;     
                            if(complet.equals(Status))
                                {
                                r1=true;
                                r2=false;
                            iv.setText(textRepresentation);       
                            iv.setTextColor(Color.parseColor("#008000"));                
                            return true;
                           }   
                            else if(notcomlet.equals(Status))
                            {
                                r2=true;
                                r1=false;
                                iv.setText(textRepresentation);       
                                iv.setTextColor(Color.RED); 
                                return true;
                            }

                            if(r1 && (getdata.startsWith("Pay of the girl:   ")))
                           {                            

                            iv.setText(textRepresentation);      

                            iv.setTextColor(Color.parseColor("#008000"));                           
                            return true;
                           }
                if(r1 && (getdata.startsWith("Pay of the boy:   ")))
                           {                            

                            iv.setText(textRepresentation);      

                            iv.setTextColor(Color.parseColor("#008000"));                           
                            return true;
            {
                        else if (r2 && (getdata.startsWith("Pay of the girl:   ")))
                        {
                            //TextView iv= (TextView) view;
                            iv.setText(textRepresentation);       
                            iv.setTextColor(Color.RED);                              
                            return true;
                        }
            else if (r2 && (getdata.startsWith("Pay of the boy:   ")))
                        {
                            //TextView iv= (TextView) view;
                            iv.setText(textRepresentation);       
                            iv.setTextColor(Color.RED);                              
                            return true;                           
                    }        
                  return false;
            }           
}

ここで私はどのように尋ねたいですか?このimages.asリファレンス

ここに画像の説明を入力

4

1 に答える 1

1

あなたのリクエストが何であるかを理解した場合、背景である1つのプロパティ要素を持つリストビューにカスタムListAdapterを使用することを提案できます。次に、listViewにデータを入力するときに、要素ごとに背景(赤または緑)を設定する必要があります。

カスタムListAdaptersについて知りたい場合は、こちらのリンクhttp://jnastase.alner.net/archive/2010/12/19/custom-android-listadapter.aspxをご覧ください。

カスタムListAdapterがBaseAdapterを拡張することを忘れないでください。

さらにサポートが必要な場合は、お気軽にお問い合わせください。

于 2012-09-20T08:49:48.963 に答える