package zhou.demo; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import com.zzhoujay.richtext.ImageHolder; import com.zzhoujay.richtext.RichText; import com.zzhoujay.richtext.callback.SimpleImageFixCallback; /** * Created by zhou on 16-6-17. */ public class ListViewActivity extends AppCompatActivity { // private static final String[] testString = new String[]{ // "

Test1

", // "

Test2

", // "

Test3

", // "

Test4

", // "

Test5

", // "

Test6

", // "

Test7

", // "

Test8

", // "

Test9

" // }; private static final String gifTest = "

Gif Test

"; private static final String[] testString = { "

Test1

", "

Test2

", "

Test3

", "

Test4

", "

Test5

", "

Test6

", "

Test7

", "

Test8

", "

Test9

" }; private static final String[] testString__ = { "

Test1

", "

Test2

", "

Test9

", "

Test3

", "

Test4

", "

Test5

", "

Test6

", // "

Test7

", // "

Test8

", // "

Test9

" }; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); ListView listView = (ListView) findViewById(R.id.listView); listView.setAdapter(new BaseAdapter() { @Override public int getCount() { return testString__.length + 1; } @Override public Object getItem(int position) { return testString[position]; } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { Holder holder; if (convertView == null) { convertView = LayoutInflater.from(ListViewActivity.this).inflate(R.layout.item_list, parent, false); holder = new Holder(convertView); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); } Log.i("RichText", "position:" + position + ",textView:" + System.identityHashCode(holder.text)); String text; if (position == 0) { text = gifTest; } else { text = testString__[position - 1]; } RichText.from(text).autoPlay(true).singleLoad(false).fix(new SimpleImageFixCallback() { @Override public void onInit(ImageHolder holder) { if (holder.isGif()) { holder.setAutoFix(false); } } }).into(holder.text); return convertView; } class Holder { public final TextView text; public Holder(View view) { text = (TextView) view.findViewById(R.id.text_item); } } }); } }