adapter 相关问题

一种设计模式,通过公共接口或类使多个接口兼容。 Gang of Four的结构设计模式之一。

View.GONE留有空白空间

我使用Firebase获得2种类型的数据,并使用RadioButton对显示的数据进行排序。一切似乎都正常,但是当其中一种数据类型被隐藏时,仍然有一个空白空间。告诉我如何...

回答 2 投票 1

[在活动中调用的类中创建适配器时,如何访问活动中的适配器?

在Android应用程序中,有以下各项:Activity_A(活动),Java_C_file_A(在Activity_A中使用的类),GridView_A(在...内部动态创建的Gridview)] >> [[

回答 1 投票 0

我的自定义RecyclerView适配器上的错误是什么?

我正在使用Recycler View,我将所有设置都设置为ok(因为它接缝了),但是总是使活动崩溃,在进行一些调试之后,我发现了它发生的地方,但是从来没有弄清楚!这是我的...

回答 3 投票 -1

是否可以从其适配器重新加载片段?

我有一个带有自定义recycerview的片段,该片段使用REST调用填充。当我单击列表项时,将弹出一个对话框。每当我退出对话框时,我都想重置该列表。我找到了...

回答 1 投票 0

我需要从后台线程访问listview适配器

我正在使用一个聊天应用程序,并且正如标题所述,我想从后台线程访问ListView的适配器以向其中添加新的元素(消息),而无需创建新的ListView和适配器...

回答 1 投票 0

将地图数据映射到同一cardview中的Recyclerview Adapter中,而无需使用任何第三方

我需要像在可扩展列表视图中那样将数据膨胀到父子关系中,但是在同一张卡片视图中,这设计起来相当复杂。因此,我试图将数据排列到Hashmap ]中。 我的要求与您的要求非常相似。我也使用了Hashmap<String,<Objects>>,但是我的解决方案对我自己来说似乎有点bug,因为我正在适配器类中动态扩展子视图,这当然不是应该的方式,但可以满足您的目的。任何建议或帮助将使代码变得更好... //主要活动类别 public class MainActivity extends AppCompatActivity { List<Data> listData1 = new ArrayList<>(); List<Data> listData2 = new ArrayList<>(); List<Data> listData3 = new ArrayList<>(); DataAdapter adapter; MapAdapter mapAdapter; Context mcontext; AlphabetIndexFastScrollRecyclerView alphabetIndexFastScrollRecyclerView; HashMap<String, List<Data>> listHash = new HashMap<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mcontext = this; listData1.add(new Data("Avik", 20.1)); listData1.add(new Data("Arnab", 21.1)); listData1.add(new Data("Anikit", 2)); listData2.add(new Data("Rajjoy", 3)); listData2.add(new Data("Sandipan", 4)); listData2.add(new Data("Arindam", 54)); listData2.add(new Data("Abhishek", 23)); listData3.add(new Data("Raju",23)); listData3.add(new Data("Nagarjuna",21)); listHash.put("Dry Wash", listData1); listHash.put("Iron", listData2); alphabetIndexFastScrollRecyclerView = findViewById(R.id.recyclerView); alphabetIndexFastScrollRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); mapAdapter = new MapAdapter(mcontext, listHash); alphabetIndexFastScrollRecyclerView.setAdapter(mapAdapter); } } //适配器类 public class MapAdapter extends RecyclerView.Adapter<MapAdapter.MyHolder> { HashMap<String, List<Data>> dataList; Context context; private SparseBooleanArray expandState = new SparseBooleanArray(); public MapAdapter(Context context, HashMap<String, List<Data>> dataList) { this.dataList = dataList; this.context = context; for (int i = 0; i < dataList.size(); i++) { expandState.append(i, false); } } @Override public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_map, null); return new MyHolder(view); } @Override public void onBindViewHolder(final MyHolder holder, final int position) { holder.setIsRecyclable(false); holder.textView_name.setText(getHashMapKeyFromIndex(dataList, position)); final boolean isExpanded = expandState.get(position); holder.expandableLayout.setVisibility(isExpanded ? View.VISIBLE : View.GONE); Log.e("val", "" + dataList.get(getHashMapKeyFromIndex(dataList, position)).size()); //llContainer holder.llContainer.removeAllViews(); double sum = 0; LayoutInflater layoutInflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i < dataList.get(getHashMapKeyFromIndex(dataList, position)).size(); i++) { Log.e("VALL", dataList.get(getHashMapKeyFromIndex(dataList, position)).get(i).title); View view = layoutInflator.inflate(R.layout.row_subcat_child, null); TextView tv_title = view.findViewById(R.id.tv_title); TextView tv_price = view.findViewById(R.id.tv_price); tv_title.setText(dataList.get(getHashMapKeyFromIndex(dataList, position)).get(i).title); tv_price.setText(String.valueOf(dataList.get(getHashMapKeyFromIndex(dataList, position)).get(i).price)); sum = sum + dataList.get(getHashMapKeyFromIndex(dataList, position)).get(i).price; holder.llContainer.addView(view); } holder.textView_total.setText(""+sum); Log.d("sum",""+sum); holder.buttonLayout.setRotation(expandState.get(position) ? 180f : 0f); holder.buttonLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { onClickButton(holder.expandableLayout, holder.buttonLayout, position); } }); } @Override public int getItemCount() { return dataList.size(); } public class MyHolder extends RecyclerView.ViewHolder { TextView textView_name,textView_total; LinearLayout expandableLayout, llContainer; RelativeLayout buttonLayout; public MyHolder(View view) { super(view); textView_total = view.findViewById(R.id.textView_total); textView_name = view.findViewById(R.id.textView_name); expandableLayout = view.findViewById(R.id.expandableLayout); buttonLayout = view.findViewById(R.id.button); llContainer = view.findViewById(R.id.llContainer); } } public static String getHashMapKeyFromIndex(HashMap hashMap, int index) { String key = null; HashMap<String, Object> hs = hashMap; int pos = 0; for (Map.Entry<String, Object> entry : hs.entrySet()) { if (index == pos) { key = entry.getKey(); } pos++; } return key; } private ObjectAnimator createRotateAnimator(final View target, final float from, final float to) { ObjectAnimator animator = ObjectAnimator.ofFloat(target, "rotation", from, to); animator.setDuration(300); animator.setInterpolator(new LinearInterpolator()); return animator; } private void onClickButton(final LinearLayout expandableLayout, final RelativeLayout buttonLayout, final int i) { //Simply set View to Gone if not expanded //Not necessary but I put simple rotation on button layout if (expandableLayout.getVisibility() == View.VISIBLE) { createRotateAnimator(buttonLayout, 180f, 0f).start(); expandableLayout.setVisibility(View.GONE); expandState.put(i, false); } else { createRotateAnimator(buttonLayout, 0f, 180f).start(); expandableLayout.setVisibility(View.VISIBLE); expandState.put(i, true); } } } //数据类 public class Data { String title; String classs; String section; double price; public Data(String title, double price) { this.title = title; this.price = price; } public Data(String title) { this.title = title; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getClasss() { return classs; } public void setClasss(String classs) { this.classs = classs; } public String getSection() { return section; } public void setSection(String section) { this.section = section; } } // row_subcat_child <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="4"> <TextView android:id="@+id/tv_title" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"></TextView> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"></TextView> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"></TextView> <TextView android:id="@+id/tv_price" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"></TextView> </LinearLayout> </RelativeLayout> // list_item_map <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/cv" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" card_view:cardCornerRadius="5dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:orientation="vertical"> <RelativeLayout android:id="@+id/buttonLayout" android:layout_width="match_parent" android:layout_height="48dp"> <RelativeLayout android:id="@+id/pparent" android:layout_width="wrap_content" android:layout_toLeftOf="@+id/button" android:layout_height="wrap_content"> <TextView android:id="@+id/textView_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:layout_toLeftOf="@+id/textView_total" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/textView_total" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_alignParentRight="true" android:layout_marginBottom="10dp" android:textSize="18sp" android:textStyle="bold" /> </RelativeLayout> <!--My dropdown Button --> <RelativeLayout android:id="@+id/button" android:layout_width="48dp" android:layout_height="48dp" android:layout_alignParentRight="true" android:layout_gravity="end" android:gravity="center"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:layout_alignParentEnd="false" android:layout_alignParentRight="false" android:background="@drawable/ic_arrow_drop_down_black_24dp" /> </RelativeLayout> </RelativeLayout> <!--The layout below is my ExpandableLayout --> <LinearLayout android:id="@+id/expandableLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <LinearLayout android:id="@+id/llContainer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:orientation="vertical"> </LinearLayout> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView>

回答 1 投票 1

如何从Firestore数据库获取Android聊天应用程序的接收方的唯一ID?

我如何使用putStringExtra和getStringExtra意向方法获取聊天应用程序的接收者的ID?目前,我仅获得该应用程序中当前登录用户的用户ID,...

回答 1 投票 0

lateinit属性movieAdapter尚未初始化Kotlin

如何解决该错误? lateinit属性movieAdapter尚未初始化。我不明白如何启动此类SearchActivity:BaseAppCompatActivity(){private lateinit ...

回答 1 投票 0

设置带有选定列表视图的项目的布局-Android

我有问题。我想使用列表视图上的选定项目重定向布局。我想重定向的布局有空的视图对象,我想用来自选定列表视图的数据填充它们...

回答 3 投票 1

使用选定的列表视图设置布局

-你好,我有问题。 -我想要重定向布局与列表视图上的选定项目。 -并且我要重定向的布局,具有空的视图对象,并且我想用来自选定列表视图的数据填充它们...

回答 1 投票 1

Android getItemId()在recyclerview中多次返回相同的ID

我正在尝试在聊天应用程序中实现setHasStableId(true)。当我以下列方式在RecyclerView适配器中重写getItemId()方法时,重写fun getItemId(position:Int):Long = ...

回答 1 投票 0

无法从适配器检索数据并将其显示为片段

我想通过适配器从回收者视图中检索数据并将其显示到片段中,但是当我想在片段中使用数据时,数据仅存储在适配器内的束中,即数据...

回答 1 投票 0

片段通信问题(尝试调用虚拟方法)

我有一个带有2个片段的选项卡式活动。我正在尝试将字符串从第一个片段传输到第二个片段,但是我得到了NULL POINTER EXCEPTION。这是MainActivity.java:...

回答 1 投票 0

VB6表单高度/宽度被命令行生成忽略

我们将尽快移出VB6,但与此同时,我们已开始从命令行在Build Server上构建VB6应用程序。问题:构建服务器具有基本视频...

回答 4 投票 1

如何从Firebase一起检索字符串和列表

我正在开发一个应用程序,您可以记录您的日常任务并将日期,日期和时间保存到数据库中。您选择日期,日期和时间,并还记录开始时间和结束时间,包括...

回答 1 投票 0

为什么在Android设备上不显示WeekDay对象的列表? Kotlin ListView

我正在编写第一个Android规划应用程序。我有一个导航抽屉和一个WeekListFragment。在片段中,我创建了WeekDay对象的数组,并尝试通过WeekAdapter显示它们。但是...

回答 1 投票 0

为数据集选择记录的策略

[在最常见的情况下,数据库中有两个表(&更多)分别称为主表(例如SalesOrderHeader)和手卷(例如SalesOrderDetail)。我们可以使用INNER JOIN和...

回答 1 投票 0

无法填充微调器,但无法访问它

public void editarEstadoSala(final Sala sala){ArrayAdapter adapter; CambiarDatosSalaWorker cambiarDatosSalaWorker =新的CambiarDatosSalaWorker(this); ...

回答 1 投票 0

viewholder onclickListener空对象引用

尝试在空对象引用public上调用接口方法'void com.example.imovie.adapter.MovieItemClickListener.onMovieClick(com.example.imovie.models.Movie,android.widget.ImageView)'...

回答 1 投票 0

RecyclerView项目不可见

RecyclerView项不可见,我正在使用字符串数组名称项test并将其传递给String数组列表,我之前使用过相同的想法并且可以正常工作listItemsTest = new ArrayList ] >>>> [[ < [ @Override public void onBindViewHolder(@NonNull RecycleViewAdapterTest.MyViewHolder holder, int position) { String value = this.ListTest.get(position); holder.textView.setText(value);// Try to make the textView public } 因为您需要在 OnBindViewHolder中将列表值设置为查看者的textview。 :(

回答 2 投票 -1

© www.soinside.com 2019 - 2024. All rights reserved.