首页 \ 问答 \ 即使在关闭活动之后仍然以编程方式保存cardview(Saving a cardview programmatically even after closing the activity)

即使在关闭活动之后仍然以编程方式保存cardview(Saving a cardview programmatically even after closing the activity)

我对android非常陌生 ,我试图通过编程来制作CardView ,我正在使用Fragment 。 通过在按钮上设置OnClick ,我可以在布局中创建卡片。 问题是关闭活动卡后没有显示。

我怎样才能保存这些卡片,关闭活动卡片后应该在那里?

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getActivity().setTitle("Okhlee");
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  view = inflater.inflate(R.layout.hawker_jobs_fragment_layout, container, false);
  context = getContext();
  button = (Button) view.findViewById(R.id.hawker_job_add_card_view_button);
  button.setOnClickListener(this);
  relativeLayout = (RelativeLayout) view.findViewById(R.id.hawker_job_relative_layout);

  return view;
}

@Override
public void onClick(View v) {
  createCardView();
}

/*Adding cardview programmatically function */
private void createCardView() {
  CardView addedCardView = new CardView(context);
  layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, height);
  addedCardView.setLayoutParams(layoutParams);
  addedCardView.setPadding(10 ,10, 10, 10);
  addedCardView.setRadius(15);
  addedCardView.setCardBackgroundColor(Color.BLUE);
  addedCardView.setMaxCardElevation(30);
  addedCardView.setMaxCardElevation(6);

  relativeLayout.addView(addedCardView);
}

对不起,我的英语不好。


I am very new to android and I am trying to make CardView by programmatically, I am using Fragment. By setting an OnClick on the button I am able to create cards in my layout. The issue is after closing the activity cards are not showing.

How can I save the cards, so after closing the activity cards should be there?

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getActivity().setTitle("Okhlee");
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  view = inflater.inflate(R.layout.hawker_jobs_fragment_layout, container, false);
  context = getContext();
  button = (Button) view.findViewById(R.id.hawker_job_add_card_view_button);
  button.setOnClickListener(this);
  relativeLayout = (RelativeLayout) view.findViewById(R.id.hawker_job_relative_layout);

  return view;
}

@Override
public void onClick(View v) {
  createCardView();
}

/*Adding cardview programmatically function */
private void createCardView() {
  CardView addedCardView = new CardView(context);
  layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, height);
  addedCardView.setLayoutParams(layoutParams);
  addedCardView.setPadding(10 ,10, 10, 10);
  addedCardView.setRadius(15);
  addedCardView.setCardBackgroundColor(Color.BLUE);
  addedCardView.setMaxCardElevation(30);
  addedCardView.setMaxCardElevation(6);

  relativeLayout.addView(addedCardView);
}

Sorry for my bad English.


原文:https://stackoverflow.com/questions/39763804
更新时间:2023-07-09 09:07

最满意答案

它会工作,这就是所有可以说的。 SyncRoot是.NET 1.1中的一个错误,没有理由继续这种做法。

Dim list = New LinkedList(Of Long)
Dim listLock = New Object
...

SyncLock(listLock)
...
End SyncLock

It will work, that's about all that can be said for it. SyncRoot was a mistake from .NET 1.1, there's no reason to continue the practice.

Dim list = New LinkedList(Of Long)
Dim listLock = New Object
...

SyncLock(listLock)
...
End SyncLock

相关问答

更多
  • List Mistery = new LinkedList<>(); 通过这种方式声明变量,你告诉编译器:我想使用List。 我想要的List的实现是LinkedList,但其余的代码应该不知道。 它需要知道的是它是一个列表。 我可能稍后改变主意并使用ArrayList,其余的代码仍然会编译,因为ArrayList也是一个List。 我还可以将另一个对象分配给同一个变量,该对象可以是ArrayList类型,也可以是CopyOnWriteArrayList,或任何其他类型的List。 由于 ...
  • 如果您有一个内部数据结构,以防止多个线程同时访问,则应始终确保要锁定的对象不是公开的。 这样做的原因是任何人都可以锁定公共对象,因此您可能会创建死锁,因为您不完全控制锁定模式。 这意味着锁定不是一个选项,因为任何人都可以锁定该对象。 同样,你不应该锁定你暴露在外面的东西。 这意味着最好的解决方案是使用内部对象,因此提示只是使用Object 。 锁定数据结构是您真正需要完全控制的,否则风险设置一个死锁场景,这可能是非常有问题的处理。 If you have an internal data structure ...
  • 不,这不对。 input.get(idx); 本身就是O(idx) ,这使得你的实现在时间上是二次的。 你可能会想要使用迭代器(或更好的listIterator )。 编辑:另外,你可以很容易地消除holdPopped有一点重新安排。 由于您通过传递大小预先分配空间(这是空间中的O(n)),因此holdPopped.add在时间和空间上都将holdPopped.add为O(1)。 IIRC, holdLL.add在时间和空间上分摊O(1)。 有时它会更多,有时更少,但总空间是n,所以它应该平均到O(n)。 ...
  • 从您的更新看来,您似乎不希望拥有大量数据,您只想使用大量数据对它们进行索引。 如果是这种情况,如果只需要true / false值,可以使用Dictionary或Dictionary 。 或者,如果您不需要区分false和“not in collection”,则可以使用HashSet 。 From your update it seems you don't want to have huge amount of ...
  • 您可以通过显式实现它来隐藏属性: object MyQueue.SyncRoot { get; set; } 它是隐藏的, 因为它已被弃用 : 我们发现基于SyncRoot的同步API在大多数情况下都不够灵活。 API允许线程安全访问集合的单个成员。 问题是,有许多场景需要锁定多个操作(例如删除一个项目并添加另一个项目)。 换句话说,它通常是使用想要选择(并且可以实际实现)正确同步策略的集合的代码,而不是集合本身。 我们发现SyncRoot实际上很少使用,并且在使用它的情况下,它实际上并没有增加太 ...
  • 如文档中所述, LinkedListNode的Value属性可用于访问存储在列表项中的值。 因此,分配CustomElement ce = this.First.Value; 。 As described in the documentation, the Value property of LinkedListNode can be used to access the value stored in the list item. Therefore, assign CustomElement ...
  • addLast在LinkedList类中声明,但不在List接口中声明。 因此,您只能使用LinkedList类型的变量来调用它。 但是,对于List类型的变量,您可以调用add来代替,因为它将元素添加到List的末尾。 当编译器看到一个List变量时,它不知道将被分配给该变量的对象的运行时类型。 因此它只能让你调用List接口的方法。 例如,您可能会为您的变量分配一个没有addLast方法的ArrayList实例,因此它不能让您调用未在List (或List的超级接口)中声明的LinkedList方法。 ...
  • 它会工作,这就是所有可以说的。 SyncRoot是.NET 1.1中的一个错误,没有理由继续这种做法。 Dim list = New LinkedList(Of Long) Dim listLock = New Object ... SyncLock(listLock) ... End SyncLock It will work, that's about all that can be said for it. SyncRoot was a mistake from .NET 1.1, there's ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)