Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在Google Glass上实现自定义CardScrollView?_Android_Google Glass_Google Gdk_Cardscrollview - Fatal编程技术网

Android 如何在Google Glass上实现自定义CardScrollView?

Android 如何在Google Glass上实现自定义CardScrollView?,android,google-glass,google-gdk,cardscrollview,Android,Google Glass,Google Gdk,Cardscrollview,我尝试使用CardScrollView而不是单个视图。我可以使用代码成功设置卡片(使用自定义布局)。当从LocalBroadcastReceiver收到新消息时,我需要更改文本字段的值。你知道我如何/在哪里解决它吗 下面是我的项目中的一些代码片段 这是CardScrollView实现的活动中的onCreate方法 private List<Integer> cards; @Override protected void onCreate(Bundle savedInstanceSt

我尝试使用CardScrollView而不是单个视图。我可以使用代码成功设置卡片(使用自定义布局)。当从LocalBroadcastReceiver收到新消息时,我需要更改文本字段的值。你知道我如何/在哪里解决它吗

下面是我的项目中的一些代码片段

这是CardScrollView实现的活动中的onCreate方法

private List<Integer> cards;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    createCards();
    xDataScrollView = new CardScrollView(this);
    xDataScrollView.setAdapter(new XDataCardScrollAdapter(cards, getLayoutInflater()));
    xDataScrollView.activate();
    setContentView(xDataScrollView);

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("newMqttData")); 
    ...
}

在您的代码中,只需像通常一样通过查找视图然后对其进行更改来更改数据

我相信这对你来说就足够了。如果您试图在运行时添加卡,您只需使用此命令通知适配器自上次以来您的数据列表已更改

xDataScrollView.getAdapter().notifyDataSetChanged();

希望这有帮助

首先感谢您的回答。我昨天找到了notifyDataSetChanged()解决方案,这在某种程度上有所帮助。但这使得我的CardScrolLView(当我想要滚动时)有点慢。你说的是找到风景。如何在CardScrollView中找到单个视图?也许这是一个愚蠢的问题,但我对此没有太多经验;t、 setText(“5000”);从我的广播接收器工作。我甚至不明白为什么这是有效的,但它是有效的。谢谢
public class XDataCardScrollAdapter extends CardScrollAdapter{

private List<Integer> cards;
private LayoutInflater inflater;
private SingletonData data;

public XDataCardScrollAdapter(List<Integer> cards, LayoutInflater inflater){
    this.cards = cards;
    this.inflater = inflater;
    this.data = SingletonData.getInstance();
}
@Override
public int getCount() {
    return cards.size();
}

@Override
public Object getItem(int i) {
    return cards.get(i);
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    return inflater.inflate(cards.get(i),viewGroup,false);
}

@Override
public int getPosition(Object o) {
    return cards.indexOf(o);
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    if(view == null){
        view = inflater.inflate(cards.get(i), viewGroup);
    }
    if(i == 0){
        TextView textView_speed = (TextView) view.findViewById(R.id.textView_speed);
        textView_speed.setText(data.getSpeed());
    ... more values here
    }else if(i==1){
        TextView textView_temperatureValue = (TextView) view.findViewById(R.id.textView_temperatureValue);
        textView_temperatureValue.setText(data.getTemperature());
    ...more values here
    }
    return view;
}
xDataScrollView.getAdapter().notifyDataSetChanged();