首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在现有Eclipse Android项目中使用cardslib时遇到问题

在现有Eclipse Android项目中使用cardslib时遇到问题
EN

Stack Overflow用户
提问于 2014-01-02 07:42:02
回答 1查看 1.2K关注 0票数 0

我正在尝试使用this card library为我试图构建的安卓应用程序的UI,但我遇到了一些问题。

作者has this guide for using the library with an existing Eclipse project,这是我一直遵循的,但我得到了多个错误。

我将该库作为“现有项目”导入到Eclipse中的Import options下,并将该项目包含在现有项目的构建路径中,但我一直收到有关缺少方法(特别是在constructor中指定的getContext()参数)的错误,即使在导入整个库之后也是如此。

下面是我的代码片段:

代码语言:javascript
复制
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardHeader;

public class MainActivity extends Activity {

    Card card = new Card(getContext());

    CardHeader header = new CardHeader(getContext());

    card.addCardHeader(header);

    CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo);

    cardView.setCard(card);

对于我的代码片段中的每一行,我都得到了以下错误:

代码语言:javascript
复制
The method getContext() is undefined for the type MainActivity

The method getContext() is undefined for the type MainActivity

Multiple markers at this line
    - Syntax error on token(s), misplaced construct(s)
    - Syntax error on token "header", VariableDeclaratorId expected after 

Multiple markers at this line
    - CardView cannot be resolved to a type
    - CardView cannot be resolved to a type
    - The method getActivity() is undefined for the type 
     MainActivity

Multiple markers at this line
    - Syntax error on token "card", VariableDeclaratorId expected after 
     this token
    - Syntax error on token(s), misplaced construct(s)

我知道这是一个非常具体的问题,但我希望我能在这里得到一个答案!

EN

回答 1

Stack Overflow用户

发布于 2014-01-14 09:57:16

你的错误与Cardslib无关。卡片构造接受当前活动的上下文。在Android中没有getContext()函数。正确的函数是getBaseContext()。

有两种方式发送它。

代码语言:javascript
复制
Card card = new Card(getBaseContext());

代码语言:javascript
复制
Card card = new Card(this);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20874455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档