私の活動にはSpinner
,EditText
、RecyclerView
があります。すべてがうまくいっていますが、私のアクティビティでEditTextをクリックするまで、私のrecyclerViewは表示されません。私は自分のコードをデバッグします。アダプターですべて渡されます。RecyclerViewが表示されていません
private void createRecycler(ArrayList<ProductNLCModel> productNLCModels) {
rcycler_productlist.setVisibility(View.VISIBLE);
rcycler_productlist.setHasFixedSize(true);
SnapHelper snapHelper = new PagerSnapHelper();
rcycler_productlist.setOnFlingListener(null);
snapHelper.attachToRecyclerView(rcycler_productlist);
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
rcycler_productlist.setLayoutManager(layoutManager);
product_name = et_productname.getText().toString();
PlaceOrderAdapter placeOrderAdapter = new PlaceOrderAdapter(productNLCModels, PlaceOrder.this, this, PlaceOrder.this, main_category, product_name);
rcycler_productlist.setAdapter(placeOrderAdapter);
placeOrderAdapter.notifyDataSetChanged();
placeOrderAdapter.notifyItemInserted(productNLCModels.size());
rcycler_productlist.smoothScrollToPosition(0);
placeOrderAdapter.setClickListener(this);
et_productname.requestFocus();
}
上記は、私のデータをrecyclerViewに渡す私の方法です。それは私のRecyclerviewにデータをロードしますが、私は原因それが表示されていないいくつかの理由にはわかりませんが、私はマニフェスト内のデータに
を示す私のEDITTEXT RecyclerViewをクリックしたとき、私は追加しました:
以下<activity
android:name=".PlaceOrder"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
android:launchMode="singleTask"/>
は私ですXML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_10">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Search Product via(Category or Compatibility)"
android:textColor="@color/black"
android:textSize="@dimen/margin_16"
/>
<Spinner
android:id="@+id/spinner_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/spinner_background" />
<android.support.design.widget.TextInputLayout
android:id="@+id/txtinput_productname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/shadow_logo"
android:theme="@style/TextLabel">
<EditText
android:id="@+id/et_productname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Name"
android:drawableRight="@drawable/searchdrawable"
android:inputType="text"
android:textSize="@dimen/margin_18" />
</android.support.design.widget.TextInputLayout>
<!--<Button-->
<!--android:id="@+id/btn_search"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="end"-->
<!--android:layout_marginRight="@dimen/margin_10"-->
<!--android:layout_marginTop="@dimen/margin_30"-->
<!--android:background="@color/colorPrimaryDarker"-->
<!--android:textColor="@color/white"-->
<!--android:textSize="13sp"-->
<!--android:padding="@dimen/margin_10"-->
<!--android:text="Search"/>-->
<android.support.v7.widget.RecyclerView
android:id="@+id/rcycler_productlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin_3"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
android:windowSoftInputMode="stateHidden|adjustPan"
android:orientation="horizontal"/>
</LinearLayout>
私はWEBAPI応答からこのメソッドを呼び出しています:getProductList(文字列strが)JSONException {をスロー
プライベート空間をProductNLCModel productNLCModel = null;
JSONArray jsonArray = new JSONArray(str);
for (int i = 0; i < jsonArray.length(); i++) {
productNLCModel = new ProductNLCModel();
JSONObject productJson = jsonArray.optJSONObject(i);
productNLCModel.setCategory(productJson.optString(WebKeys.Key_Category));
productNLCModel.setS_no(productJson.optString(WebKeys.Sno));
productNLCModel.setProductId(productJson.optString(WebKeys.ProductId));
productNLCModel.setImagePath(productJson.optString(WebKeys.ImagePath));
productNLCModel.setProductName(productJson.optString(WebKeys.Key_ProductName));
productNLCModel.setCompatible(productJson.optString(WebKeys.Compatible));
productNLCModel.setSpecification(productJson.optString(WebKeys.Specification));
productNLCModel.setMRP(productJson.optString(WebKeys.MRP));
productNLCModel.setDP(productJson.optString(WebKeys.DP));
productNLCModel.setNLC(productJson.optString(WebKeys.NLC));
if (i == 0) {
JSONArray categoryDetailArray = productJson.optJSONArray(WebKeys.GetCategoryDetail);
for (int j = 0; j < categoryDetailArray.length(); j++) {
JSONObject discountstructure = categoryDetailArray.optJSONObject(j);
str_categorydetail = str_categorydetail + discountstructure.optString(WebKeys.Turnover) + "@" + discountstructure.optString(WebKeys.Discount) + "%,";
}
}
productNLCModels.add(productNLCModel);
}
if(jsonArray.length()>0){
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
category_detail.setSelected(true);
str_categorydetail = str_categorydetail.substring(0, str_categorydetail.length() - 1);
category_detail.setText(str_categorydetail);
} catch (Exception e) {
e.printStackTrace();
}
createRecycler(productNLCModels);
}
});
}
}
なぜこの行があるのですか?et_productname.requestFocus(); それを削除してみてください – Pulkit
edittextをクリックしたときに私のrecyclerviewが表示されているので、後で追加しました。フォーカスを要求することで完了すると思います –
android:focusableInTouchMode = "true" android:descendantFocusability = "beforeDescendants"そのためにも? – Pulkit