0

I've been searching the web and Stack Overflow and I can't seem to find an answer that explains clearly what I'm trying to do:

I'd like to display a table inside of my widget, I know widgets are limited to only a few layout types, so I thought the easiest way to do this would be to make a vertical linear layout, then add each row as a horizontal linear layout with textviews as cells inside each one. After coding this in a loop, I can't seem to figure out how to put the linearlayout into the widget...

Here's a more visual idea:

<Vertical linear layout>
 <text view "title">
 <some number of LinearLayouts horizontally - H>
   <some number of textviews>
 </ll -h>
 <text view "footer">
</ll - v>

I'm obviously very new to Android so any help would be great.

4

1 に答える 1

0

これを機能させる方法は次のとおりです。

rv2 = new RemoteViews(this.getApplicationContext()
                                    .getPackageName(), R.layout.datarow);
                            if(tr.hasClass("title"))
                                i = 1;
                            else
                                i = 0;
                            for (Element td : tds) {
                                if (td.getElementsByTag("a").size() > 0) {
                                    Elements anchors = td.getElementsByTag("a");
                                    td.text(anchors.get(0).text());
                                    rv2.setTextViewText(R.id.textView2,
                                            td.text());
                                } else {
                                    switch (i) {
                                    case 0:
                                        rv2.setTextViewText(R.id.textView1,
                                                td.text());
                                        i++;
                                        break;
                                    case 1:
                                        rv2.setTextViewText(R.id.textView3,
                                                td.text());
                                        i++;
                                        break;
                                    case 2:
                                        rv2.setTextViewText(R.id.textView4,
                                                td.text());
                                        i++;
                                        break;
                                    case 3:
                                        rv2.setTextViewText(R.id.textView5,
                                                td.text());
                                        i++;
                                        break;
                                    case 4:
                                        rv2.setTextViewText(R.id.textView6,
                                                td.text());
                                        i++;
                                        break;
                                    default:
                                        break;
                                    }
                                }
                            }
                            remoteViews.addView(R.id.layout, rv2);

見栄えが悪く、スイッチを使用するのは好きではありませんが、テキストビューを反復処理する方法がわかりませんでした。誰かが私により良い答えをくれる場合に備えて、これをしばらく開いたままにします。

于 2012-07-12T15:32:48.037 に答える