私はpreferencactivityにalertdialogを表示しようとしていますが、recyclerviewはこのように表示されます。 RecyclerView View error On PreferanceActivity
私のコード....
cata_manage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(preference.getContext());
LayoutInflater inflater = (LayoutInflater)preference.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View dialogView = inflater.inflate(R.layout.cata_manage, null);
dialogBuilder.setView(dialogView);
final AlertDialog alertDialog2 = dialogBuilder.create();
final RecyclerView cata_list = (RecyclerView) dialogView.findViewById(R.id.cata_manage_recycler);
update_recycler_cata("Expenses", cata_list,preference.getContext());
alertDialog2.show();
return false;
}
});
private void update_recycler_cata(String cata, RecyclerView catalist,Context context) {
DBHelper mydb = new DBHelper(this);
Cursor catas = null;
if (cata == null || Objects.equals(cata, "Expenses")) {
catas = mydb.fetchall_cata_ex_names();
} else if (Objects.equals(cata, "Income")) {
catas = mydb.fetchall_cata_in_names();
}
CataRecyclerAdapter adapter = new CataRecyclerAdapter(catas, context, catalist);
RecyclerView.LayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(context);
catalist.setLayoutManager(mLayoutManager);
// recyclerView.setHasFixedSize(true);
catalist.setAdapter(adapter);
}
CataRecyclerAdapter.java
public class CataRecyclerAdapter extends RecyclerView.Adapter<CataRecyclerAdapter.RecyclerViewHolder> {
private Cursor cursor;
private Context context;
private RecyclerView catalist;
CataRecyclerAdapter(Cursor cursor, Context context, RecyclerView catalist) {
this.cursor = cursor;
this.context = context;
this.catalist = catalist;
}
@Override
public CataRecyclerAdapter.RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.catamanage_singleitem, parent, false);
RecyclerViewHolder recyclerViewHolder = new RecyclerViewHolder(view);
return recyclerViewHolder;
}
@Override
public void onBindViewHolder(CataRecyclerAdapter.RecyclerViewHolder holder, final int position) {
cursor.moveToPosition(position);
holder.item.setText(cursor.getString(1));
}
@Override
public int getItemCount() {
return cursor.getCount();
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
ImageButton edit, delete;
TextView item;
@TargetApi(Build.VERSION_CODES.KITKAT)
public RecyclerViewHolder(View itemView) {
super(itemView);
item = (TextView) itemView.findViewById(R.id.textView34);
edit = (ImageButton) itemView.findViewById(R.id.imageButton2);
delete = (ImageButton) itemView.findViewById(R.id.imageButton3);
}
}
}
XMLコード(catamanage_singleitem.xml)。 ..
私は多くの方法を試してみましまし<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/textView34"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="TextView"
android:textSize="18sp" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
app:srcCompat="@android:drawable/ic_menu_edit" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
app:srcCompat="@android:drawable/ic_menu_delete" />
</LinearLayout>
</android.support.v7.widget.CardView>
、どのように私はこの問題を解決することができますか。? catamanage_singleitem
の中にimageviewを追加しましたが、イメージビューが表示されません。どのように私はこれを解決することができます、これは私が取るコンテキスト値のためですか?
に
app:src ="@android:drawable/ic_menu_edit"
にEDIT
変更
app:srcCompat="@android:drawable/ic_menu_edit"
コードの下に試してみてください –私の質問を更新しました – Tom
recyclerviewのlist item.xmlとupdate_recycler_cataメソッドを投稿できます – Raghavendra