package zhou.demo; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.zzhoujay.richtext.RichText; /** * Created by zhou on 16-6-17. */ public class RecyclerViewActivity extends AppCompatActivity { private static final String[] testString1 = new String[]{ "

Test1

", "

Test2

", "

Test3

", "

Test4

", "

Test5

", "

Test6

", "

Test7

", "

Test8

", "

Test9

", }; // private static final String[] testString1 = new String[]{ // "

Test1

hello

", // "

Test2

hello

", // "

Test3

hello

", // "

Test4

hello

", // "

Test5

hello

", // "

Test6

hello

", // "

Test7

hello

", // "

Test8

hello

", // "

Test9

hello

", // }; private static final String[] testStringImage = { "http://www.aikf.com/ask/resources/images/facialExpression/qq/1.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/2.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/3.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/4.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/5.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/6.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/7.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/8.gif", "http://www.aikf.com/ask/resources/images/facialExpression/qq/9.gif", }; private static final String[] testString = { "

Test1

", "

Test2

", "

Test3

", "

Test4

", "

Test5

", "

Test6

", "

Test7

", "

Test8

", "

Test9

", }; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recycler); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(new RecyclerView.Adapter() { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new Holder(LayoutInflater.from(RecyclerViewActivity.this).inflate(R.layout.item_list, parent, false)); } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof Holder) { Holder h = (Holder) holder; RichText.from(testString1[position]).singleLoad(false).into(h.text); } } @Override public int getItemCount() { return testString1.length; } class Holder extends RecyclerView.ViewHolder { public TextView text; public TextView id; public Holder(View itemView) { super(itemView); text = (TextView) itemView.findViewById(R.id.text_item); // id = (TextView) itemView.findViewById(R.id.text_id); } } }); } }