0

https://github.com/nadavfima/cardsui-for-android

我正在使用这个库来创建一张卡片,它的标题很简单,内容中的列表视图更复杂一些。我遇到的问题是我无法从文件“card_ex.xml”访问任何 xml 对象,因为“错误”视图被设置为内容视图。

MainActivity.java

package com.cardsui.example;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.fima.cardsui.views.CardUI;


public class MainActivity extends Activity {

ListView lv;

private CardUI mCardView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // init CardView
    mCardView = (CardUI) findViewById(R.id.cardsview);
    mCardView.setSwipeable(false);


    MyCard idag = new MyCard("Idag");

    idag.getView(this);
    // add one card, and then add another one to the last stack.
    mCardView.addCard(new MyCard("Idag"));


    lv = (ListView) findViewById(android.R.id.item_list);

    String[] items = new String[] {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7"};
    ArrayAdapter<String> adapter =
      new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice,      items);

 //     lv.setAdapter(adapter);


    // draw cards
    mCardView.refresh();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}

card_ex.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="8dp"
    android:paddingRight="8dp" >

    <TextView
        android:id="@+id/title"
        style="@style/CardTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="title" />
</LinearLayout>

<View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_marginTop="4dp"
    android:background="@color/stroke" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/selectable_background_cardbank"
    android:gravity="center_vertical"
    android:padding="4dp" >


    <ListView
        android:id="@+id/item_list"
        style="@style/CardText"
        android:layout_width="wrap_content"
        android:layout_height="400dp"
        android:divider="@color/stroke"
        android:dividerHeight="1dp"
        android:ellipsize="end" />


</LinearLayout>

</LinearLayout>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:background="@drawable/background"
android:id="@+id/cards">

<com.fima.cardsui.views.CardUI
    android:id="@+id/cardsview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

我想操作不在内容视图中的id“item_list”,而是在另一个xml文件“card_ex”中。

无论如何,我可以在当前设置的内容视图中获得一个 id 吗?

4

0 回答 0