Androidstudio增加列表项内容:在TextView的右侧增加一个TextView(具体文本内容为当前时间)
时间: 2023-05-21 08:06:44 浏览: 52
您可以使用 RecyclerView 和自定义适配器来实现此内容的增加。您需要在适配器类中的 onBindViewHolder 方法中获取当前时间,并将其设置为右侧 TextView 的文本内容。以下是一个简单的例子:
```
class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
...
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
// 获取当前时间
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
String currentTime = sdf.format(new Date());
// 设置右侧 TextView 的文本内容为当前时间
holder.timeTextView.setText(currentTime);
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView mainTextView;
TextView timeTextView;
MyViewHolder(View itemView) {
super(itemView);
mainTextView = itemView.findViewById(R.id.main_text_view);
timeTextView = itemView.findViewById(R.id.time_text_view);
}
}
}
```
请注意,在上述示例中,我们假设您将右侧 TextView 的 ID 设置为 "time_text_view"。您需要根据实际情况进行更改。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)