如何将存储在recyclerview适配器中的数组列表转换为字符串?

时间:2019-01-18 14:46:54

标签: android arraylist type-conversion recycler-adapter stringbuilder

不是字符串数组。我正在通过AsyncTask下载电影评论,并将列表存储在Recyclerview Adapter中的数组中。万一数据不可用,returnReviewData方法中会有一个敬酒消息。我想显示一条短信。

我知道如何使用String构建器将ArrayList转换为String。但是,我在这里无法做到这一点(包括像它们在下面的线程中所做的那样)。是否可以在if语句中执行此操作?预先谢谢你。

Best way to convert an ArrayList to a string

how to convert arraylist into string?

public class DetailActivity extends AppCompatActivity implements MovieTrailerAdapter.MovieTrailerAdapterOnClickHandler, AsyncTaskReviewInterface {

//Tag for the log messages
    private static final String TAG = DetailActivity.class.getSimpleName();

    private ArrayList<MovieReview> simpleJsonMovieReviewData = new ArrayList<>();
 private Context context;
    private RecyclerView mRecyclerViewReview;
 private MovieReviewAdapter movieReviewAdapter;
 Movie movie;

@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

   context = getApplicationContext();
        mRecyclerViewReview = (RecyclerView) findViewById(R.id.recyclerview_review);
   movieReviewAdapter = new MovieReviewAdapter(simpleJsonMovieReviewData, context);
      mRecyclerViewReview.setAdapter(movieReviewAdapter);


        RecyclerView.LayoutManager mReviewLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        mRecyclerViewReview.setLayoutManager(mReviewLayoutManager);

 if (getIntent() != null && getIntent().getExtras() != null)
        {
            movie = getIntent().getExtras().getParcelable("Movie");
   movieId = movie.getMovieId();

            MovieReviewAsyncTask myReviewTask = new MovieReviewAsyncTask(this);
            myReviewTask.execute(movieId);
}

public void returnReviewData(ArrayList<MovieReview> simpleJsonMovieReviewData)
    {
        movieReviewAdapter = new MovieReviewAdapter(simpleJsonMovieReviewData, DetailActivity.this);
        mRecyclerViewReview.setAdapter(movieReviewAdapter);

        if (simpleJsonMovieReviewData.size() == 0)
        {
            Toast.makeText(DetailActivity.this, R.string.review_unavailable, Toast.LENGTH_SHORT).show();
        }
    }
}

0 个答案:

没有答案