2011-01-13 4 views
0

私はAndroid開発を初めて使いました。私は、インターフェイスのようなListViewでActivityを作成しましたが、List内の各項目(行)が異なる要素を持つため、ListViewを使用しません。私は、ScrollView内にLinearLayoutsを含めることで正常に作成しましたが、XMLは乱雑に見えます。また、それぞれの内部LinearLayoutsにonClickListenerを追加しました。Androidのさまざまな要素を含む各アイテムのリストを作成する

これを行うには良い方法がありますか?

ありがとうございました。

あなたはアダプタ&をサブクラス化することができます

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
<ScrollView 
    android:id="@+id/ScrollView01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"> 
    <LinearLayout 
    android:id="@+id/LinearLayout02" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <LinearLayout 
    android:id="@+id/wo_status_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@color/desc_button" 
    android:focusable="true" 
    android:padding="3dp"> 
    <TextView 
    android:id="@+id/wo_status" 
    android:text="@string/wo_status" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
    <TextView 
    android:id="@+id/wo_status" 
    android:text="Waiting for Parts" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
    </LinearLayout> 
    <LinearLayout 
    android:id="@+id/wo_prob_desc_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@color/desc_button" 
    android:focusable="true" 
    android:padding="3dp"> 
    <TextView 
    android:id="@+id/wo_prob_desc" 
    android:text="@string/wo_status" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
    <TextView 
    android:id="@+id/wo_prob_desc" 
    android:text="New problem" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
    </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
</LinearLayout> 

答えて

2

私はLedgeristの主導的な開発者です。私たちがやったことは、上記のようにgetViewを実装したAdapterのサブクラスを作成することでした。

getViewメソッドの中では、ViewHolderオブジェクトを作成します。これは、Web全体の多くのチュートリアルに示されていると思います。 ViewHolderの内側に表示する可能性のある各コントロールのインスタンスを作成したいと思うでしょう。セルを実装するには、setVisibilityメソッドを使用して、表示しないコントロールをすべてGONEに設定する必要があります。これは便利です

希望、

ジェームズK.、リードデベロッパー www.vervv.com | [email protected]

Twitterでフォローする: http://twitter.com/vervv

+0

Ledgeristの主任開発者が私の質問に答えるとは思っていませんでした:-)。私はsetVisibilityを使う考えが大好きです。これは、各セルに別々のレイアウトを使用するよりも優れていると思います。 – dezull

0

よろしく、

dezull)(getViewメソッドを実装します。 アダプタでは、複数のビューを使用できます。また、任意のビューに対してsetOnClickListenerを設定できます。 あなたが好きな子供たちと一緒にlinearLayoutsをretuenする; アンドロイドにはさまざまな目的のためのアダプタサブクラスが既に用意されています。 ArrayAdapter、SimpleAdapter、CursorAdapter、..etc; 次にListView.setAdapter(yourAdapter);

別のトリックは、scrollViewでアダプタを使用することです。 LinearLayoutをscrollViewの子として設定し、次にlinearLayout.addview(adapter.getView(...));

希望します。

+0

@vervv私は、アダプタを使用する例を見てきましたが、それは各要素が一意であることができるのですか? (例えば、ボタンが1つあり、別の画像があるなど)。具体的には、Androidの「環境設定」のようなアクティビティを作成したいのですが、フォームとして(Android MarketplaceのLedgeristアプリケーションのように)作成したいと考えています。 – dezull

関連する問題