你好每一个我试图将视图转换为片段,但它显示错误的错误转换视图片段请给我解决方案我怎么能做到这一点。我在listview的baseadapter中使用它
谢谢,我的代码在这里
在pages.add();
中出现错误package okay.adapters;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ParseException;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import com.Okay.Webservices.Service_LikeImage;
import com.okay.R;
import com.okay.comments.OkayComments;
import com.okay.fonts.fontsFamily;
import com.okay.lazyloading.ImageLoaderRelativeLayout;
import com.okay.lazyloading.mageLoaderWallUserImage;
import com.okay.properties.okayWallProps;
public class wallAdapter extends BaseAdapter {
wallAdapterProps objProp = new wallAdapterProps();
ImageLoaderRelativeLayout imageLoader_RelativeLayout;
mageLoaderWallUserImage imageLoader;
int imagePsotioninPager;
public wallAdapter(Fragment act, List<okayWallProps> wallData) {
objProp.wallDataList = wallData;
objProp.activity = act.getActivity();
objProp.context = objProp.activity.getApplicationContext();
imageLoader_RelativeLayout = new ImageLoaderRelativeLayout(
objProp.context);
imageLoader = new mageLoaderWallUserImage(objProp.context);
}
@Override
public int getCount() {
return objProp.wallDataList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return objProp.wallDataList.get(position).wallPost_ID;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater mInflater = (LayoutInflater) objProp.activity
.getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = mInflater.inflate(R.layout.adapter_walllayout, null);
}
// Get Controls
final viewHolder vh = new viewHolder();
vh.txtview_Question = (TextView) v.findViewById(R.id.textView1);
vh.textview_CommentCount = (TextView) v
.findViewById(R.id.textVew_WallTotalComments);
vh.textview_LikeCount = (TextView) v
.findViewById(R.id.textVew_WallTotalokay);
vh.ViewPager_Images = (ViewPager) v.findViewById(R.id.pager);
vh.imageview_Profile = (ImageView) v
.findViewById(R.id.imageview_userImage);
vh.textview_PostDate=(TextView)v.findViewById(R.id.textView_PostDate);
vh.textview_UserName=(TextView)v.findViewById(R.id.textVew_WallUserName);
// SetDatato controls
//Set Data
vh.txtview_Question
.setText(objProp.wallDataList.get(position).wallPost_Name);
vh.txtview_Question.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
vh.textview_UserName.setText(objProp.wallDataList.get(position).wallPost_User_Name);
vh.textview_UserName.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
vh.textview_PostDate.setText(convertDate(objProp.wallDataList.get(position).wallPost_Date));
vh.textview_PostDate.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),false));
// Set pager
Vector<Fragment> pages = new Vector<Fragment>();
for (int i = 0; i < objProp.wallDataList.get(position).wallPost_Images_Data
.size(); i++) {
final int imagePosion=i;
LayoutInflater mInflaterImage = (LayoutInflater) objProp.activity
.getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View vImage = mInflaterImage.inflate(R.layout.wallimagepageradaper, null);
ImageView imageView=(ImageView)vImage.findViewById(R.id.imageView1);
CheckBox chk=(CheckBox)vImage.findViewById(R.id.checkBox1);
imageLoader_RelativeLayout.DisplayImage(objProp.wallDataList
.get(position).wallPost_Images_Data.get(i).qst_Wall_Image,
imageView);
//Get Controls
/* vh.textView_Percentage=(TextView)vImage.findViewById(R.id.textView_PercentCount);
vh.textView_percentVoteCount=(TextView)vImage.findViewById(R.id.textView1_PercentVoteCount);
//Set Data
vh.textView_Percentage.setText(objProp.wallDataList.get(position).wallPost_Images_Data.get(i).qst_Wall_Image_Percentage+"%");
vh.textView_Percentage.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
vh.textView_percentVoteCount.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
vh.textView_percentVoteCount.setText(objProp.wallDataList.get(position).wallPost_Images_Data.get(i).qst_Wall_Image_LikeCount+" Votes");
*/
chk.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
new Service_LikeImage(objProp.activity).execute(objProp.wallDataList
.get(position).wallPost_Images_Data.get(imagePosion).qst_Wall_ImageID+"");
}
});
/*//RelativeLayout layoutImage=new RelativeLayout(objProp.activity.getApplicationContext());
vh.imageView_PostImage = new ImageView(objProp.context);
vh.imageView_PostImage.setId(getID());
imageLoader_RelativeLayout.DisplayImage(objProp.wallDataList
.get(position).wallPost_Images_Data.get(i).qst_Wall_Image,
vh.imageView_PostImage);*/
pages.add(object)
}
CustomPagerAdapter adap = new CustomPagerAdapter(objProp.activity.getSupportFragmentManager(),pages);
vh.ViewPager_Images.setAdapter(adap);
vh.ViewPager_Images.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
vh.textview_CommentCount.setText(objProp.wallDataList
.get(position).wallPost_Images_Data.get(arg0).qst_Wall_Image_CommentCount
+ " Comments");
vh.textview_CommentCount.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
vh.textview_LikeCount.setText(objProp.wallDataList
.get(position).wallPost_Images_Data.get(arg0).qst_Wall_Image_LikeCount
+ " Okay");
vh.textview_LikeCount.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
imagePsotioninPager=arg0;
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
vh.textview_CommentCount.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(objProp.activity, OkayComments.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("wallPostPosition", position);
intent.putExtra("imageNumber",imagePsotioninPager );
objProp.activity.startActivity(intent);
}
});
imageLoader.DisplayImage(objProp.wallDataList.get(position).wallPost_User_Image,
vh.imageview_Profile);
String totComments = objProp.wallDataList.get(position).wallPost_Images_Data
.get(0).qst_Wall_Image_CommentCount + "";
vh.textview_CommentCount
.setText(totComments+" Comments");
vh.textview_CommentCount.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
vh.textview_LikeCount
.setText(objProp.wallDataList.get(position).wallPost_Images_Data
.get(0).qst_Wall_Image_LikeCount + " Okay");
vh.textview_LikeCount.setTypeface(fontsFamily.getFont(objProp.activity.getApplicationContext(),true));
return v;
}
public class viewHolder {
TextView txtview_Question;
TextView textview_CommentCount;
TextView textview_LikeCount;
TextView textview_UserName;
TextView textview_PostDate;
ViewPager ViewPager_Images;
ImageView imageview_Profile;
/*TextView textView_Percentage;
TextView textView_percentVoteCount;
*/
// Image in ViewPager
ImageView imageView_PostImage;
}
public int getID() {
int max = 1000000;
int min = 0;
// Usually this can be a field rather than a method variable
Random rand = new Random();
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
}
private String convertDate(String strngdate) {
SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
java.util.Date date = null;
try
{
date = form.parse(strngdate);
}
catch (ParseException e)
{
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SimpleDateFormat postFormater = new SimpleDateFormat("MMM dd, yyyy HH:mm");
String newDateStr = postFormater.format(date);
return newDateStr;
}
public String getFormattedDate( long smsTimeInMilis) {
Calendar smsTime = Calendar.getInstance();
smsTime.setTimeInMillis(smsTimeInMilis);
Calendar now = Calendar.getInstance();
final String timeFormatString = "h:mm aa";
final String dateTimeFormatString = "EEEE, MMMM d, h:mm aa";
final long HOURS = 60 * 60 * 60;
if(now.get(Calendar.DATE) == smsTime.get(Calendar.DATE) ){
return "Today " + DateFormat.format(timeFormatString, smsTime);
}else if(now.get(Calendar.DATE) - smsTime.get(Calendar.DATE) == 1 ){
return "Yesterday " + DateFormat.format(timeFormatString, smsTime);
}else if(now.get(Calendar.YEAR) == smsTime.get(Calendar.YEAR)){
return DateFormat.format(dateTimeFormatString, smsTime).toString();
}else
return DateFormat.format("MMMM dd yyyy, h:mm aa", smsTime).toString();
}
}
答案 0 :(得分:0)
View
和Fragment
个对象无法转换为另一个对象,因为它们具有非常不同的超类,也不是接口。如果您不明白为什么我建议继续阅读http://developer.android.com/develop/index.html。
答案 1 :(得分:0)
在片段中,添加class ="...."
。
答案 2 :(得分:0)
您不能执行此操作(将视图投射到片段),但是如果您需要获取添加的片段,请说您使用支持片段管理器添加了片段,然后可以通过TAG从UI中获取当前片段
<body>
<button style="display:block" onclick="on_click()">Move the box</button>
<div id="circle">
</div>
</body>