これが可能かどうかわからないので、問題を提示してから、これが可能かどうかを確認します。TableRow
だから私はテーブルにいくつかの簡単な情報を含むセクションを持っていますが、ユーザーがクリックすると行が展開されて追加情報 (最初のビューでは不要なもの) が表示されるように調整したいと思います。同じ行が再選択されると折りたたまれます。は(基本的な概要を示すため、layout:height で 45dip に固定されていTableRow
ます) でセットアップされ、 3 つ(1 つは日付ラベル、もう 1 つはタイトル、最後はメッセージ) があります。ユーザーが [ I want to expand ] をクリックすると、最後のメッセージ全体が表示されるようになりますGridLayout
TextViews
TableRow
TableRow
TextView
読むことができます(現在は、スペースを節約するために最初の行のみを表示しているため)。コードが役立つかどうかはわかりませんが、TableRow
レイアウトのコードは次のとおりです。
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="?android:attr/selectableItemBackground">
<GridLayout
android:layout_width="fill_parent"
android:layout_height="45dip"
android:columnCount="2"
android:rowCount="3"
android:layout_marginTop="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="44dip"
android:id="@+id/alertDateText"
android:gravity="center_vertical"
android:textColor="@color/black"
android:layout_marginLeft="10dip"
android:layout_row="0"
android:layout_rowSpan="2"
android:text="12/12/2013"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/alertTitleText"
android:layout_marginLeft="10dip"
android:layout_column="1"
android:layout_row="0"
android:textColor="@color/black"
android:textStyle="bold"
android:text="Alert Title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/alertMessageText"
android:layout_marginLeft="10dip"
android:layout_column="1"
android:layout_row="1"
android:textStyle="italic"
android:textColor="@color/DarkSlateGray"
android:text="Alert Message"/>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="@color/LightSlateGray"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_row="2"
android:layout_columnSpan="2"/>
</GridLayout>
</TableRow>
TextViews
そして、ここにからのデータを入力するアクティビティがありますWebService
(展開/折りたたみ機能を実行できることを確認したかったので、その部分はまだ接続していません。そうしないと、このデザインを変更する必要があります)範囲:
Integer alertCount = 3;
for (int i = 0; i < alertCount; i++) {
TableRow alertRow = (TableRow)inflater.inflate(R.layout.table_row_alert_holder, alertTable, false);
alertRow.setClickable(true);
alertRow.setTag(i);
alertRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
TextView dateText = (TextView)alertRow.findViewById(R.id.alertDateText);
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
dateText.setText(format.format(date));
TextView alertHeader = (TextView)alertRow.findViewById(R.id.alertTitleText);
alertHeader.setText("Alert Title Number: " + i);
TextView alertMessage = (TextView)alertRow.findViewById(R.id.alertMessageText);
alertMessage.setText("This is a really long message that will go in one of the alerts since it notifies the user about some kind of form that was declined in the service area");
alertTable.addView(alertRow);
}