Timeline of Android implementation
There was a timeline project discussed in the group yesterday. I never touched it. I thought it was very difficult. After the study, I realized that the surface was full of dummies. Using listview, I could achieve it, and there was nothing new.
Just put it bluntly.
You can customize images and text.
There is nothing to say, just go to the code! I believe you can understand
1. layout file of the timeline item
2. model of images and text
package com.sdufe.thea.guo.model;public class TimeLineModel {private int imageview;private String text;public int getImageview() {return imageview;}public void setImageview(int imageview) {this.imageview = imageview;}public String getText() {return text;}public void setText(String text) {this.text = text;}public TimeLineModel(int imageview, String text) {super();this.imageview = imageview;this.text = text;}}
3 Timeline Adapter
package com.sdufe.thea.guo.adapter;import java.util.List;import com.sdufe.thea.guo.R;import com.sdufe.thea.guo.model.TimeLineModel;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.TextView;public class TimeLineAdapter extends BaseAdapter {Context context;List
list;public TimeLineAdapter(Context context, List
list) {super();this.context = context;this.list = list;}@Overridepublic int getCount() {if (list!=null) {return list.size();}return 0;}@Overridepublic Object getItem(int position) {if (list!=null) {return list.get(position);}return null;}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHold hold;if (convertView==null) {hold=new ViewHold();convertView=LayoutInflater.from(context).inflate(R.layout.timeline_item, null);convertView.setTag(hold);}else {hold=(ViewHold) convertView.getTag();}hold.imageView=(ImageView) convertView.findViewById(R.id.left_imageview);hold.show=(TextView) convertView.findViewById(R.id.right_textview);hold.imageView.setImageResource(list.get(position).getImageview());hold.show.setText(list.get(position).getText());return convertView;}static class ViewHold{public TextView show;public ImageView imageView;}}
The files in the layout are the same as those used by listview. paste the code to help you and me
Package com. sdufe. thea. guo; import java. util. arrayList; import java. util. list; import android. app. activity; import android. OS. bundle; import android. view. menu; import android. view. window; import android. widget. listView; import com. sdufe. thea. guo. adapter. timeLineAdapter; import com. sdufe. thea. guo. model. timeLineModel; public class MainActivity extends Activity {private ListView listView; private List
List; private TimeLineAdapter adapter; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. activity_main); initData (); initView ();} private void initView () {listView = (ListView) findViewById (R. id. listview); adapter = new TimeLineAdapter (this, list); listView. setAdapter (adapter);} private void initData () {list = new ArrayList
(); List. add (new TimeLineModel (R. drawable. medicalcheck2, "Haha"); list. add (new TimeLineModel (R. drawable. nurse_visit2, "Haha"); list. add (new TimeLineModel (R. drawable. nursingcareplan2, ""); list. add (new TimeLineModel (R. drawable. medicalcheck2, "Haha"); list. add (new TimeLineModel (R. drawable. nurse_visit2, ""); list. add (new TimeLineModel (R. drawable. nursingcareplan2, "ke") ;}@ Overridepublic boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}
OK. The code is finished. Do not hide it by the appearance of many apps.
Code: http://download.csdn.net/detail/elinavampire/8179393
Github: https://github.com/zimoguo/TimeLineDemo