问题描述:

I am trying to create a RecyclerView, each row is a horizontal scrolling list. but now the contents of RecyclerView are not visible. Data are visible on android 4.1.1 but when i try to test on android 5 or 6, data are not visible.

Here is my WinnersListAdapter Adapter:

 public class WinnersListAdapter extends RecyclerView.Adapter<WinnersListAdapter.WinnersCardViewHolder>

{

Context context;

LayoutInflater inflater;

List<ListLottery> lotteryList;

public WinnersListAdapter(List<ListLottery> loteries,Context context){

this.context = context;

this.lotteryList = loteries;

inflater = LayoutInflater.from(context);

}

@Override

public WinnersListAdapter.WinnersCardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View v = inflater.inflate(R.layout.prevlotterycards_layout,parent,false);

Toast.makeText(context,"Hi",Toast.LENGTH_SHORT).show();

WinnersListAdapter.WinnersCardViewHolder viewHolder = new WinnersListAdapter.WinnersCardViewHolder(v);

return viewHolder;

}

@Override

public void onBindViewHolder(WinnersListAdapter.WinnersCardViewHolder holder, int position) {

final ListLottery lottery = lotteryList.get(position);

holder.lottery_date.setText(lottery.getLotteryDate());

holder.lottery_date.setTag(holder);

holder.itemView.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent(context,WinnerActivity.class);

intent.putExtra("lotteryId",lottery.getLotteryId());

context.startActivity(intent);

}

});

}

@Override

public int getItemCount() {

return lotteryList.size();

}

class WinnersCardViewHolder extends RecyclerView.ViewHolder {

TextView lottery_date;

CardView card_lotteryList;

public WinnersCardViewHolder(View itemView) {

super(itemView);

lottery_date = (TextView) itemView.findViewById(R.id.l_lottery_date);

card_lotteryList = (CardView) itemView.findViewById(R.id.card_lotteryList);

}

}

}

Here is WinnerActivity Code:

public class WinnerActivity extends AppCompatActivity {

String lotteryId;

TextView lottery_date,name,city,prize;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_winner);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

Bundle bundle = getIntent().getExtras();

lotteryId = bundle.getString("lotteryId");

lottery_date = (TextView) findViewById(R.id.w_lottery_date);

name = (TextView) findViewById(R.id.w_name);

city = (TextView) findViewById(R.id.w_city);

prize = (TextView) findViewById(R.id.w_prize);

NextLotteryAPI();

}

public void NextLotteryAPI(){

AsyncHttpClient client = new AsyncHttpClient();

HashMap<String, String> param = new HashMap<String, String>();

Toast.makeText(getBaseContext(), "lottery_id = "+lotteryId, Toast.LENGTH_SHORT).show();

param.put("lottery_id", lotteryId);

RequestParams params = new RequestParams(param);

final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar1);

//Displaying Progressbar

progressBar.setVisibility(View.VISIBLE);

setProgressBarIndeterminateVisibility(true);

client.get("http://192.168.43.82/malamallottery.com/getPrevWinner", params, new JsonHttpResponseHandler() {

@Override

public void onStart() {

Toast.makeText(getBaseContext(), "demo 1", Toast.LENGTH_SHORT).show();

}

@Override

public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject responseBody) {

try {

if ((int) responseBody.get("result") == 200) {

lottery_date.setText(responseBody.getJSONObject("message").get("lottery_date").toString());

name.setText(responseBody.getJSONObject("message").get("u_name").toString());

city.setText(responseBody.getJSONObject("message").get("city").toString());

prize.setText(responseBody.getJSONObject("message").get("l_name").toString());

} else if ((int) responseBody.get("result") == 500) {

Toast.makeText(getBaseContext(), "Something goes wrong", Toast.LENGTH_SHORT).show();

}

} catch (JSONException e) {

e.printStackTrace();

}

//Hiding the progressbar

progressBar.setVisibility(View.GONE);

}

// @Override

public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, org.json.JSONObject responseBody, Throwable error) {

Toast.makeText(getBaseContext(), "Something goes wrong", Toast.LENGTH_SHORT).show();

}

@Override

public void onRetry(int retryNo) {

Toast.makeText(getBaseContext(), "demo 4", Toast.LENGTH_SHORT).show();

// called when request is retried

}

});

}

}

Here is my content layout :

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/content_winner_list"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:background="@drawable/gradient"

app:layout_behavior="@string/appbar_scrolling_view_behavior"

tools:context="malamallottery.corporate1.co.in.WinnerListActivity"

tools:showIn="@layout/activity_winner_list">

<android.support.v7.widget.RecyclerView

android:id="@+id/rv_winners"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:scrollbars="vertical"/>

<ProgressBar

android:id="@+id/progressBar1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true" />

</RelativeLayout>

Here is my data CardView Layout :

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:tag="cards main container">

<android.support.v7.widget.CardView

android:id="@+id/card_lotteryList"

xmlns:card_view="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="wrap_content"

card_view:cardBackgroundColor="@color/colorPrimaryDark"

card_view:cardCornerRadius="10dp"

card_view:cardElevation="5dp"

android:foreground="?android:attr/selectableItemBackground"

card_view:cardUseCompatPadding="true">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

<LinearLayout

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_marginTop="0dp"

android:layout_weight="2"

android:orientation="vertical"

>

<TextView

android:id="@+id/l_lottery_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#fff"

android:layout_gravity="center_horizontal"

android:layout_marginTop="10dp"

android:layout_marginBottom="10dp"

android:text="Lottery Date (10)"

android:textAppearance="?android:attr/textAppearanceLarge"/>

</LinearLayout>

</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

相关阅读:
Top