Android的基础适配器不适配器的所有行 [英] android base adapter does not adapter all rows
问题描述
我有两个日期时间2014年12月1日和12/10 / 2014.i改变日期时间格式,我还检查了不同的有两个日期时间,我也有增加之间的天datetimes.for更多信息
12月1日,12月2日,12月3日..... 12月10日
这是我的源
I have two datetimes 12/01/2014 and 12/10/2014.i changed datetime format and i also checked different between there two datetime and i also incremented days between there datetimes.for more information 1 dec,2 dec,3 dec .....10 dec this is a my source
public class MoviesRolls extends Fragment {
public final static String TAG = MoviesRolls.class.getSimpleName();
private ListView holllistview;
private HollAdapters adapter;
public static ArrayList<CinemaInfoModel> cinemaInfoArray;
public static CinemaInfoModel timeInfo;
public static MoviesRolls newInstance() {
return new MoviesRolls();
}
@SuppressLint("SimpleDateFormat")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater
.inflate(R.layout.moviesholls, container, false);
holllistview = (ListView) rootView.findViewById(R.id.holllistview);
holllistview = (ListView) rootView.findViewById(R.id.holllistview);
ServerItems mainItem = MainmoviesList.arrayOfList
.get(MainmoviesList.mPosition);
ArrayList<CinemaModel> cinemas = mainItem.getCinema();
ArrayList<CinemaInfoModel> infos = new ArrayList<CinemaInfoModel>();
for (int i = 0; i < cinemas.size(); i++) {
CinemaModel cinema = cinemas.get(i);
cinemaInfoArray = cinema.getCinemTimeInfo();
for (int j = 0; j < cinemaInfoArray.size(); j++) {
timeInfo = cinemaInfoArray.get(j);
Log.wtf("starttime1",
timeInfo.getTimeformat().get(MainmoviesList.mPosition));
Log.wtf("endtime1",
timeInfo.getEndTimeFormat().get(
MainmoviesList.mPosition));
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date _d;
try {
SimpleDateFormat new_df = new SimpleDateFormat("d MMM");
_d = df.parse(timeInfo.getTimeformat().get(
MainmoviesList.mPosition));
Date _d1 = df.parse(timeInfo.getEndTimeFormat().get(
MainmoviesList.mPosition));
String datetimeis = getDateDiffString(_d1, _d);
int differentdays = Integer.parseInt(datetimeis);
Log.e("Different is ", String.valueOf(differentdays));
for (int k = 0; k < differentdays; k++) {
String datetimeformat = dateFormatter(timeInfo
.getTimeformat().get(MainmoviesList.mPosition));
Date datetime = new_df.parse(datetimeformat);
Calendar cal = Calendar.getInstance();
cal.setTime(datetime);
cal.add(Calendar.DATE, k);
datetime = cal.getTime();
String ttime = new_df.format(datetime);
timeInfo.setStartTimePeriod(ttime);
System.out.println(ttime);
infos.add(timeInfo);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
adapter = new HollAdapters(getActivity(), infos);
holllistview.setAdapter(adapter);
}
return rootView;
}
public String getDateDiffString(Date dateOne, Date dateTwo) {
long timeOne = dateOne.getTime();
long timeTwo = dateTwo.getTime();
long oneDay = 1000 * 60 * 60 * 24;
long delta = (timeTwo - timeOne) / oneDay;
if (delta > 0) {
for (int i = 0; i < delta; i++) {
}
return String.valueOf(delta);
} else {
delta *= -1;
return String.valueOf(delta);
}
}
public static String dateFormatter(String inputDate) {
String inputFormat = "MM/dd/yyyy";
String outputFormat = "d MMM";
Date parsed = null;
String outputDate = "";
try {
SimpleDateFormat df_input = new SimpleDateFormat(inputFormat,
new Locale("en", "US"));
SimpleDateFormat df_output = new SimpleDateFormat(outputFormat,
new Locale("en", "US"));
parsed = df_input.parse(inputDate);
outputDate = df_output.format(parsed);
// Log.wtf("outputDate", outputDate);
} catch (Exception e) {
outputDate = inputDate;
}
return outputDate;
}
}
这是我的baseadapter XML code
} this is a my baseadapter xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@android:color/transparent" >
<TextView
android:id="@+id/adapter_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignLeft="@+id/imageView1"
android:layout_alignRight="@+id/imageView1"
android:layout_marginBottom="15dp"
android:gravity="center"
android:paddingLeft="5dp"
android:text="day"
android:textColor="#c42a29"
android:textSize="13dp" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/imageView1"
android:layout_below="@+id/adapter_day"
android:layout_marginRight="25dp"
android:background="@drawable/justline" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:background="@drawable/adapter_circle" />
</RelativeLayout>
我logend,我可以显示在日志中的所有信息。这是我的日志猫结果一>(我是新用户,我不能张贴图片)
在我的选择,我有我的baseadapter问题,因为在我的适配器只能显示第一日期时间(1 DEC)
这是我的基本适配器code
i logend and i can show all information in log.this is a my log cat result (i'm new user and i can't post image) in my option i have problem in my baseadapter because in adapter i can show only first datetime(1 dec) this is a my base adapter code
public class HollAdapters extends BaseAdapter {
private Context mContext;
private final ArrayList<CinemaInfoModel> hollitems;
public HollAdapters(Context context, ArrayList<CinemaInfoModel> hollitems) {
mContext = context;
this.hollitems = hollitems;
}
@Override
public int getCount() {
return hollitems.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressLint("ViewHolder")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderItem viewHolder;
if (convertView == null) {
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(R.layout.cinema_holl_adapter,
parent, false);
viewHolder = new ViewHolderItem();
viewHolder.start_time = (TextView) convertView
.findViewById(R.id.adapter_day);
convertView.setTag(viewHolder);
}
viewHolder = (ViewHolderItem) convertView.getTag();
CinemaInfoModel objectItem = hollitems.get(position);
if (objectItem != null) {
if (position < objectItem.getStartTimePeriod().size()) {
String starttimes = objectItem.getStartTimePeriod().get(
position);
viewHolder.start_time.setText(starttimes);
}
}
return convertView;
}
static class ViewHolderItem {
private TextView start_time;
}
}
这是我divice的截图
正如我所说的,我可以只显示日期时间先1 Dec.i不知道什么是我baseadapter.if任何一个错误都知道的解决方案,请帮助我
谢谢
this is a my divice's screenshot as i said i can show only first datetime 1 Dec.i have no idea what is a wrong in my baseadapter.if anyone knows solution please help me thanks
推荐答案
删除围绕ViewHolder提取}其他
块。移动支架初始化到如果{
块之后。现在尝试。
Remove the } else
block around the ViewHolder extraction. Move the Holder initialization to after the if{
block. And try now.
if (convertView == null) {
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(R.layout.cinema_holl_adapter,
parent, false);
ViewHolderItem newViewHolder = new ViewHolderItem();
newViewHolder.start_time = (TextView) convertView
.findViewById(R.id.adapter_day);
convertView.setTag(newViewHolder);
}
ViewHolderItem viewHolder = (ViewHolderItem) convertView.getTag(); //This should be called always
/* Rest of your code */
编辑:
这是什么块呢?
What does this block do?
if (position < objectItem.getStartTimePeriod().size()) {
String starttimes = objectItem.getStartTimePeriod().get(
position);
viewHolder.start_time.setText(starttimes);
}
这篇关于Android的基础适配器不适配器的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!