Android CardView 实现

huangapple go评论82阅读模式
英文:

Android CardView implementation

问题

我创建了一个带有列表视图的Android应用程序。每当点击一个元素时,它会传递意图到卡片视图。我的布局文件中只有一个单独的卡片视图,并且对于列表视图中的每个元素都使用它。

对于每个列表项,在Java中为CardView定义了不同的实现,从一个Java文件传递意图到另一个文件。

请问这样做是一种好的做法吗?即在多个元素上使用单个卡片视图和RecyclerView,并在程序中更改它们的文本。我还没有看到有人这样做过。

编辑
@Ankit,类似于...

类似于

<android.support.v7.widget.RecyclerView/>
</LinearLayout>```

**教程页面1**
```public class Lesson_Galaxy_One extends AppCompatActivity {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lesson_galaxy);
}```

**教程页面2**
```public class Lesson_Galaxy_Two extends AppCompatActivity {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lesson_galaxy);
}```

**教程页面3**
```public class Lesson_Galaxy_Three extends AppCompatActivity {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lesson_galaxy);
}```

每个页面都有不同的元素用于RecyclerView的CardView,从一个页面传递意图到另一个页面。

<details>
<summary>英文:</summary>

I created an Android app with list view. Whenever the an element is clicked, it passes intent to cardview.I have a  single cardview in my layout file, and use it for every element in the listView. 

For each list item, I define different implementation for the CardView in Java passing intents from one java file to the other. .

Please is this a good practice using a single card view and Recycler View for multiple elements changing their text programmatically. I haven&#39;t seen anyone do something like that.

**Edit**
@Ankit something like ...


Something like 
```&lt;LinearLayout
&gt;
&lt;android.support.v7.widget.RecyclerView/&gt;
&lt;/LinearLayout&gt;```



**Tutorial page 1**
       ```public class Lesson_Galaxy_One extends AppCompatActivity
{ super.onCreate(savedInstanceState);
        setContentView(R.layout.lesson_galaxy);

}```


**Tutorial 2**
       ```public class Lesson_Galaxy_Two extends AppCompatActivity
{ super.onCreate(savedInstanceState);
        setContentView(R.layout.lesson_galaxy);

}```

**Tutorial 3**
       ```public class Lesson_Galaxy_Three extends AppCompatActivity
{ super.onCreate(savedInstanceState);
        setContentView(R.layout.lesson_galaxy);

}```


Each with different elements for the RecyclerView&#39;s CardView with intents being passed from one to the other.

</details>


# 答案1
**得分**: 1

不会有任何问题,可以将单个卡片视图用于多个列表项。这完全没有问题。

<details>
<summary>英文:</summary>

There won&#39;t be any issues of using a single card view for multiple list items.It&#39;s totally fine .

</details>



huangapple
  • 本文由 发表于 2020年7月26日 20:30:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/63100150.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定