我有一个xml,其中包含4个包含在LinearLayout内的布局,我在我的ListAdapter中膨胀这个xml。但问题是我能够访问前三个包含布局的元素但不幸的是我无法做任何第4个包括布局的变化例如。更改我的第四个包含布局中存在的ImageView的图像源。它也没有响应任何点击事件。我已经清理了我的项目并重新启动了很多次,但没有任何反应。我调试了很多,但我没有得到任何异常。 FindViewById可以工作,但它无法更改ImageView的背景资源(包含在布局中)。我现在还不知道发生了什么。所以请帮助。
这是我的适配器代码和xmls。
package com.embazaar.controllers;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.VideoView;
import com.codebrew.embazaar.ChatActivity;
import com.codebrew.embazaar.UserProfileActivity;
import com.codebrew.lazyloading.ImageLoader;
import com.codebrew.mbazaar.R;
import com.embazaar.connection.Connection;
import com.embazaar.constants.EmBazaarApplicationGlobal;
import com.embazaar.constants.EmBazaarConstants;
import com.embazaar.objects.HeartBeatInfoBean;
public class FeedListAdapter extends BaseAdapter {
private LayoutInflater layoutInflater;
private ArrayList<HeartBeatInfoBean> heartBeatList;
private FragmentActivity activity;
ImageLoader loader;
int screenWidth, imageWidth, imageHeight;
SharedPreferences prefs;
// private boolean isVideoPlaying = false;
@SuppressWarnings("deprecation")
public FeedListAdapter(FragmentActivity activity,
ArrayList<HeartBeatInfoBean> heartBeatList) {
this.activity = activity;
this.heartBeatList = heartBeatList;
loader = new ImageLoader(this.activity);
layoutInflater = LayoutInflater.from(this.activity);
screenWidth = this.activity.getWindowManager().getDefaultDisplay()
.getWidth();
imageWidth = screenWidth - 20;
imageHeight = (screenWidth * 9) / 16;
prefs = this.activity.getSharedPreferences("embazaar", 0);
}
@Override
public int getCount() {
return heartBeatList.size();
}
@Override
public Object getItem(int arg0) {
return arg0;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(final int arg0, View convertView, ViewGroup arg2) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.feedslistcontents,
null);
holder.ll_statusLayout = (LinearLayout) convertView
.findViewById(R.id.ll_statusLayout);
holder.rl_listWhite = (RelativeLayout) convertView
.findViewById(R.id.rl_listWhite);
holder.rl_feedLayout = (RelativeLayout) convertView
.findViewById(R.id.rl_feedLayout);
holder.rl_feedEventLayout = (RelativeLayout) convertView
.findViewById(R.id.rl_feedEventLayout);
holder.rl_statusVideoLayout = (RelativeLayout) convertView
.findViewById(R.id.rl_statusVideoLayout);
holder.rl_itemVideoLayout = (RelativeLayout) convertView
.findViewById(R.id.rl_itemVideoLayout);
holder.rl_itemOverlayLayout = (RelativeLayout) convertView
.findViewById(R.id.rl_itemOverlayLayout);
holder.topBar = (RelativeLayout) convertView
.findViewById(R.id.topbar);
holder.iv_userPicStatus = (ImageView) convertView
.findViewById(R.id.iv_userPicStatus);
holder.iv_userPicItem = (ImageView) convertView
.findViewById(R.id.iv_userPicItem);
holder.iv_itemPic = (ImageView) convertView
.findViewById(R.id.iv_itemPic);
holder.iv_like = (ImageView) convertView.findViewById(R.id.iv_like);
holder.iv_comment = (ImageView) convertView
.findViewById(R.id.iv_comment);
holder.iv_share = (ImageView) convertView
.findViewById(R.id.iv_share);
holder.iv_dislike = (ImageView) convertView
.findViewById(R.id.iv_dislike);
holder.iv_statusImage = (ImageView) convertView
.findViewById(R.id.iv_statusImage);
holder.iv_eventImage = (ImageView) convertView
.findViewById(R.id.iv_eventImage);
holder.iv_statusVideoPlay = (ImageView) convertView
.findViewById(R.id.iv_statusVideoplay);
holder.iv_itemVideoPlay = (ImageView) convertView
.findViewById(R.id.iv_itemVideoPlay);
holder.iv_contact = (ImageView) convertView
.findViewById(R.id.iv_contact);
holder.tv_status = (TextView) convertView
.findViewById(R.id.tv_status);
holder.tv_usernameStatus = (TextView) convertView
.findViewById(R.id.tv_usernameStatus);
holder.tv_statusLikes = (TextView) convertView
.findViewById(R.id.tv_statusLikes);
holder.tv_statusComments = (TextView) convertView
.findViewById(R.id.tv_statusComments);
holder.tv_statusPostedTime = (TextView) convertView
.findViewById(R.id.tv_statusPostedTime);
holder.tv_usernameItem = (TextView) convertView
.findViewById(R.id.tv_usernameItem);
holder.tv_itemName = (TextView) convertView
.findViewById(R.id.tv_itemName);
holder.tv_likeCommentItem = (TextView) convertView
.findViewById(R.id.tv_likeCommentItem);
holder.tv_itemPostedTime = (TextView) convertView
.findViewById(R.id.tv_itemPostedTime);
holder.tv_itemPrice = (TextView) convertView
.findViewById(R.id.tv_itemPrice);
holder.tv_itemRentTime = (TextView) convertView
.findViewById(R.id.tv_itemRentTime);
holder.tv_itemTradeFor = (TextView) convertView
.findViewById(R.id.tv_itemTradeFor);
holder.tv_cat = (TextView) convertView.findViewById(R.id.tv_cat);
holder.tv_eventDate = (TextView) convertView
.findViewById(R.id.tv_eventdate);
holder.tv_eventDesc = (TextView) convertView
.findViewById(R.id.tv_eventdesc);
holder.tv_eventMonth = (TextView) convertView
.findViewById(R.id.tv_eventmonth);
holder.tv_eventTitle = (TextView) convertView
.findViewById(R.id.tv_eventtitle);
holder.tv_usernameEvent = (TextView) convertView
.findViewById(R.id.tv_usernameevent);
holder.tv_eventLikeComment = (TextView) convertView
.findViewById(R.id.tv_eventLikeComment);
holder.vv_statusVideo = (VideoView) convertView
.findViewById(R.id.vv_statusVideo);
holder.vv_itemVideo = (VideoView) convertView
.findViewById(R.id.vv_itemVideo);
holder.iv_statusImage.getLayoutParams().width = imageWidth;
holder.iv_statusImage.getLayoutParams().height = imageHeight;
holder.rl_statusVideoLayout.getLayoutParams().width = imageWidth;
holder.rl_statusVideoLayout.getLayoutParams().height = imageHeight;
holder.rl_itemVideoLayout.getLayoutParams().width = imageWidth;
holder.rl_itemVideoLayout.getLayoutParams().height = imageHeight;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (heartBeatList.get(arg0).getLiked().equals("1")) {
holder.iv_like.setImageResource(R.drawable.btn_like_pressed);
holder.iv_dislike.setImageResource(R.drawable.btn_dislike_normal);
holder.iv_like.setEnabled(false);
holder.iv_dislike.setEnabled(true);
} else if (heartBeatList.get(arg0).equals("-1")) {
holder.iv_dislike.setImageResource(R.drawable.btn_dislike_pressed);
holder.iv_like.setImageResource(R.drawable.btn_like_normal);
holder.iv_like.setEnabled(true);
holder.iv_dislike.setEnabled(false);
} else {
holder.iv_like.setImageResource(R.drawable.btn_like_normal);
holder.iv_dislike.setImageResource(R.drawable.btn_dislike_normal);
holder.iv_like.setEnabled(true);
holder.iv_dislike.setEnabled(true);
}
if (heartBeatList.get(arg0).getType().equals("1")) {
holder.ll_statusLayout.setVisibility(View.VISIBLE);
holder.rl_feedLayout.setVisibility(View.GONE);
holder.rl_feedEventLayout.setVisibility(View.GONE);
setStatus(heartBeatList.get(arg0), holder);
} else if (heartBeatList.get(arg0).getType().equals("2")) {
holder.ll_statusLayout.setVisibility(View.GONE);
holder.rl_feedEventLayout.setVisibility(View.GONE);
holder.rl_feedLayout.setVisibility(View.VISIBLE);
setBazaarItem(heartBeatList.get(arg0), holder);
} else {
holder.ll_statusLayout.setVisibility(View.GONE);
holder.rl_feedLayout.setVisibility(View.GONE);
holder.rl_feedEventLayout.setVisibility(View.VISIBLE);
setEventItem(heartBeatList.get(arg0), holder);
}
setClickListeners(heartBeatList.get(arg0), holder);
return convertView;
}
private void setClickListeners(final HeartBeatInfoBean infobean,
final ViewHolder holder) {
holder.iv_statusVideoPlay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// isVideoPlaying = true;
holder.iv_statusVideoPlay.setVisibility(View.GONE);
holder.vv_statusVideo.start();
}
});
holder.vv_statusVideo
.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0) {
// isVideoPlaying = false;
holder.iv_statusVideoPlay.setVisibility(View.VISIBLE);
}
});
holder.iv_itemVideoPlay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// isVideoPlaying = true;
holder.iv_itemVideoPlay.setVisibility(View.GONE);
holder.rl_itemOverlayLayout.setVisibility(View.GONE);
holder.vv_itemVideo.start();
}
});
holder.vv_itemVideo.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0) {
// isVideoPlaying = false;
holder.iv_itemVideoPlay.setVisibility(View.VISIBLE);
holder.rl_itemOverlayLayout.setVisibility(View.VISIBLE);
}
});
holder.iv_userPicItem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(activity, UserProfileActivity.class);
i.putExtra("user_id", infobean.getUser_id());
activity.startActivity(i);
activity.overridePendingTransition(0, 0);
}
});
holder.iv_contact.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(activity, ChatActivity.class);
i.putExtra("user_id2", infobean.getUser_id());
i.putExtra("user2_name", infobean.getUsername());
activity.startActivity(i);
activity.overridePendingTransition(0, 0);
}
});
holder.iv_userPicStatus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(activity, UserProfileActivity.class);
i.putExtra("user_id", infobean.getUser_id());
activity.startActivity(i);
activity.overridePendingTransition(0, 0);
}
});
holder.iv_like.setOnClickListener(new OnClickListener() {
@SuppressWarnings("unchecked")
@Override
public void onClick(View v) {
holder.iv_like.setEnabled(false);
holder.iv_dislike.setEnabled(true);
holder.iv_dislike
.setImageResource(R.drawable.btn_dislike_normal);
holder.iv_like.setImageResource(R.drawable.btn_like_pressed);
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("user_id", prefs.getString("user_id", ""));
params.put("post_id", infobean.getId());
params.put("post_type", infobean.getType());
new Like().execute(params);
}
});
holder.iv_dislike.setOnClickListener(new OnClickListener() {
@SuppressWarnings("unchecked")
@Override
public void onClick(View v) {
holder.iv_like.setEnabled(false);
holder.iv_dislike.setEnabled(true);
holder.iv_like.setImageResource(R.drawable.btn_like_normal);
holder.iv_dislike
.setImageResource(R.drawable.btn_dislike_pressed);
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("user_id", prefs.getString("user_id", ""));
params.put("post_id", infobean.getId());
params.put("post_type", infobean.getType());
new Dislike().execute(params);
}
});
holder.iv_share.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
share();
}
});
}
private void setStatus(HeartBeatInfoBean heartBeatInfoBean,
ViewHolder holder) {
try {
int number = 0;
loader.DisplayImage(heartBeatInfoBean.getUimage(),
holder.iv_userPicStatus, 1);
holder.tv_usernameStatus.setText(heartBeatInfoBean.getUsername());
holder.tv_statusPostedTime.setText(heartBeatInfoBean
.getTime_since());
holder.tv_statusLikes.setText(heartBeatInfoBean.getLike_count()
+ " Likes");
holder.tv_statusComments.setText(heartBeatInfoBean.getComments()
+ " Comments");
if (heartBeatInfoBean.getImagesList().size() > 0) {
number = 1;
} else if (!heartBeatInfoBean.getVideo().equals("")) {
number = 2;
} else if (!heartBeatInfoBean.getCheckin_loc_name().equals("")) {
number = 3;
} else {
number = 0;
}
if (!heartBeatInfoBean.getTitle().equals("")) {
if (number == 1) {
holder.iv_statusImage.setVisibility(View.VISIBLE);
holder.rl_statusVideoLayout.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.VISIBLE);
holder.tv_status.setText(heartBeatInfoBean.getTitle());
if (EmBazaarApplicationGlobal.isLoad()) {
loader.DisplayImage1(heartBeatInfoBean.getImagesList()
.get(0)
+ "&w="
+ imageWidth
+ "&h="
+ imageHeight + "&zc=0", holder.iv_statusImage,
R.drawable.img_place);
}
} else if (number == 2) {
holder.iv_statusImage.setVisibility(View.GONE);
holder.rl_statusVideoLayout.setVisibility(View.VISIBLE);
holder.iv_statusVideoPlay.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.VISIBLE);
holder.tv_status.setText(heartBeatInfoBean.getTitle());
if (EmBazaarApplicationGlobal.isLoad()) {
holder.vv_statusVideo.setVideoURI(Uri
.parse(heartBeatInfoBean.getVideo()));
// if (!isVideoPlaying) {
// isVideoPlaying = true;
holder.vv_statusVideo.start();
// }
}
} else if (number == 3) {
holder.iv_statusImage.setVisibility(View.GONE);
holder.rl_statusVideoLayout.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.VISIBLE);
int begIndex = heartBeatInfoBean.getTitle().indexOf(
heartBeatInfoBean.getCheckin_loc_name());
int endIndex = begIndex
+ heartBeatInfoBean.getCheckin_loc_name().length();
String firstString = heartBeatInfoBean.getTitle()
.substring(0, begIndex + 1);
String secondString = heartBeatInfoBean.getTitle()
.substring(endIndex + 1,
heartBeatInfoBean.getTitle().length());
holder.tv_status.setText(
Html.fromHtml(firstString + "<b color='blue'>"
+ heartBeatInfoBean.getCheckin_loc_name()
+ "</b>)" + secondString),
TextView.BufferType.SPANNABLE);
} else {
holder.iv_statusImage.setVisibility(View.GONE);
holder.rl_statusVideoLayout.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.VISIBLE);
holder.tv_status.setText(heartBeatInfoBean.getTitle());
}
} else {
switch (number) {
case 0:
holder.iv_statusImage.setVisibility(View.GONE);
holder.rl_statusVideoLayout.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.VISIBLE);
holder.tv_status.setText(heartBeatInfoBean.getTitle());
break;
case 1:
holder.iv_statusImage.setVisibility(View.VISIBLE);
holder.rl_statusVideoLayout.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.GONE);
if (EmBazaarApplicationGlobal.isLoad()) {
loader.DisplayImage1(heartBeatInfoBean.getImagesList()
.get(0)
+ "&w="
+ imageWidth
+ "&h="
+ imageHeight + "&zc=0", holder.iv_statusImage,
R.drawable.img_place);
}
break;
case 2:
holder.iv_statusImage.setVisibility(View.GONE);
holder.rl_statusVideoLayout.setVisibility(View.VISIBLE);
holder.tv_status.setVisibility(View.GONE);
holder.iv_statusVideoPlay.setVisibility(View.GONE);
if (EmBazaarApplicationGlobal.isLoad()) {
holder.vv_statusVideo.setVideoURI(Uri
.parse(heartBeatInfoBean.getVideo()));
// if (!isVideoPlaying) {
// isVideoPlaying = true;
holder.vv_statusVideo.start();
// }
}
break;
case 3:
holder.iv_statusImage.setVisibility(View.GONE);
holder.rl_statusVideoLayout.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.VISIBLE);
int begIndex = heartBeatInfoBean.getTitle().indexOf(
heartBeatInfoBean.getCheckin_loc_name());
int endIndex = begIndex
+ heartBeatInfoBean.getCheckin_loc_name().length();
String firstString = heartBeatInfoBean.getTitle()
.substring(0, begIndex + 1);
String secondString = heartBeatInfoBean.getTitle()
.substring(endIndex + 1,
heartBeatInfoBean.getTitle().length());
holder.tv_status.setText(
Html.fromHtml(firstString + "<b color='blue'>"
+ heartBeatInfoBean.getCheckin_loc_name()
+ "</b>)" + secondString),
TextView.BufferType.SPANNABLE);
break;
default:
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void setBazaarItem(HeartBeatInfoBean heartBeatInfoBean,
ViewHolder holder) {
try {
GradientDrawable topBg = (GradientDrawable) holder.topBar
.getBackground();
loader.DisplayImage(heartBeatInfoBean.getUimage(),
holder.iv_userPicItem, 1);
holder.tv_usernameItem.setText("by "
+ heartBeatInfoBean.getUsername());
holder.tv_itemPostedTime.setText(heartBeatInfoBean.getTime_since());
holder.tv_itemName.setText(heartBeatInfoBean.getTitle());
holder.tv_likeCommentItem.setText(heartBeatInfoBean.getLike_count()
+ " likes " + heartBeatInfoBean.getComments()
+ " comments");
if (heartBeatInfoBean.getUser_id().equals(
prefs.getString("user_id", ""))) {
holder.iv_contact.setVisibility(View.GONE);
} else {
holder.iv_contact.setVisibility(View.VISIBLE);
}
if (!heartBeatInfoBean.getVideo().equals("")) {
holder.vv_itemVideo.setVisibility(View.VISIBLE);
holder.iv_itemPic.setVisibility(View.GONE);
holder.rl_itemOverlayLayout.setVisibility(View.GONE);
holder.iv_itemVideoPlay.setVisibility(View.GONE);
if (EmBazaarApplicationGlobal.isLoad()) {
holder.vv_itemVideo.setVideoURI(Uri.parse(heartBeatInfoBean
.getVideo()));
// if (!isVideoPlaying) {
// isVideoPlaying = true;
holder.vv_itemVideo.start();
// }
}
} else {
holder.vv_itemVideo.setVisibility(View.GONE);
holder.iv_itemPic.setVisibility(View.VISIBLE);
holder.rl_itemOverlayLayout.setVisibility(View.VISIBLE);
if (EmBazaarApplicationGlobal.isLoad()) {
loader.DisplayImage1(
heartBeatInfoBean.getImagesList().get(0) + "&w="
+ imageWidth + "&h=" + imageHeight
+ "&zc=0", holder.iv_itemPic,
R.drawable.img_place);
}
}
if (heartBeatInfoBean.getSub_type().equals("1")) {
topBg.setColor(Color.parseColor("#FFA500"));
topBg.setStroke(1, Color.parseColor("#FFA500"));
holder.tv_cat.setText("FOR SALE");
holder.tv_itemRentTime.setVisibility(View.GONE);
holder.tv_itemTradeFor.setVisibility(View.GONE);
holder.tv_itemPrice.setVisibility(View.VISIBLE);
holder.tv_itemPrice.setText("$" + heartBeatInfoBean.getPrice());
} else if (heartBeatInfoBean.getSub_type().equals("2")) {
topBg.setColor(Color.parseColor("#66c823"));
topBg.setStroke(1, Color.parseColor("#66c823"));
holder.tv_cat.setText("FOR RENT");
holder.tv_itemRentTime.setVisibility(View.VISIBLE);
holder.tv_itemRentTime
.setText(heartBeatInfoBean.getRent_type());
holder.tv_itemTradeFor.setVisibility(View.GONE);
holder.tv_itemPrice.setVisibility(View.VISIBLE);
holder.tv_itemPrice.setText("$" + heartBeatInfoBean.getPrice());
} else if (heartBeatInfoBean.getSub_type().equals("3")) {
topBg.setColor(Color.parseColor("#e0056d"));
topBg.setStroke(1, Color.parseColor("#e0056d"));
holder.tv_cat.setText("FOR TRADE");
holder.tv_itemRentTime.setVisibility(View.GONE);
holder.tv_itemTradeFor.setVisibility(View.VISIBLE);
holder.tv_itemPrice.setVisibility(View.GONE);
holder.tv_itemTradeFor.setText("Trade For "
+ heartBeatInfoBean.getTrade_for());
} else {
topBg.setColor(Color.parseColor("#701a7d"));
topBg.setStroke(1, Color.parseColor("#701a7d"));
holder.tv_cat.setText("FOR FREE");
holder.tv_itemRentTime.setVisibility(View.GONE);
holder.tv_itemTradeFor.setVisibility(View.GONE);
holder.tv_itemPrice.setVisibility(View.GONE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void setEventItem(HeartBeatInfoBean heartBeatInfoBean,
ViewHolder holder) {
GradientDrawable listWhite = (GradientDrawable) holder.rl_listWhite
.getBackground();
listWhite.setColor(Color.parseColor("#FFFFFF"));
listWhite.setStroke(1, Color.parseColor("#FFFFFF"));
holder.tv_eventDate.setText(getDate(heartBeatInfoBean.getEvent_date()));
holder.tv_eventMonth
.setText(getMonth(heartBeatInfoBean.getEvent_date()));
holder.tv_eventDesc.setText(heartBeatInfoBean.getDescription());
holder.tv_usernameEvent
.setText("by " + heartBeatInfoBean.getUsername());
holder.tv_eventTitle.setText(heartBeatInfoBean.getTitle());
holder.tv_eventLikeComment.setText(heartBeatInfoBean.getLike_count()
+ " Likes " + heartBeatInfoBean.getComments() + " Comments");
if (EmBazaarApplicationGlobal.isLoad()) {
loader.DisplayImage1(heartBeatInfoBean.getImagesList().get(0)
+ "&w=" + imageWidth + "&h=" + imageHeight + "&zc=0",
holder.iv_eventImage, R.drawable.img_place);
}
}
static class ViewHolder {
ImageView iv_userPicStatus, iv_userPicItem, iv_like, iv_comment,
iv_share, iv_dislike, iv_statusImage, iv_eventImage,
iv_itemPic, iv_statusVideoPlay, iv_itemVideoPlay, iv_contact;
VideoView vv_statusVideo, vv_itemVideo;
TextView tv_status, tv_usernameStatus, tv_statusLikes,
tv_statusComments, tv_statusPostedTime, tv_cat,
tv_usernameItem, tv_itemName, tv_likeCommentItem,
tv_itemPostedTime, tv_itemPrice, tv_itemRentTime,
tv_itemTradeFor, tv_eventDate, tv_eventMonth, tv_eventTitle,
tv_usernameEvent, tv_eventDesc, tv_eventLikeComment;
LinearLayout ll_statusLayout;
RelativeLayout rl_feedLayout, topBar, rl_feedEventLayout, rl_listWhite,
rl_statusVideoLayout, rl_itemVideoLayout, rl_itemOverlayLayout;
}
public class Like extends
AsyncTask<Hashtable<String, String>, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Hashtable<String, String>... params) {
String jsonString = "";
try {
jsonString = Connection.sendPostData(
EmBazaarConstants.ACTION_LIKE, params[0]);
} catch (Exception e) {
e.printStackTrace();
}
return jsonString;
}
@Override
protected void onPostExecute(final String result) {
super.onPostExecute(result);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONObject jObject = new JSONObject(result);
if (jObject.getString("success").equals("1")) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
public class Dislike extends
AsyncTask<Hashtable<String, String>, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Hashtable<String, String>... params) {
String jsonString = "";
try {
jsonString = Connection.sendPostData(
EmBazaarConstants.ACTION_DISLIKE, params[0]);
} catch (Exception e) {
e.printStackTrace();
}
return jsonString;
}
@Override
protected void onPostExecute(final String result) {
super.onPostExecute(result);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONObject jObject = new JSONObject(result);
if (jObject.getString("success").equals("1")) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
@SuppressLint({ "SimpleDateFormat", "DefaultLocale" })
private String getMonth(String event_date) {
String month = "";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Date date1 = format.parse(event_date);
SimpleDateFormat sdf = new SimpleDateFormat("MMM");
month = sdf.format(date1);
} catch (ParseException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return month.toUpperCase();
}
@SuppressLint("SimpleDateFormat")
private String getDate(String event_date) {
String date = "";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Date date1 = format.parse(event_date);
SimpleDateFormat sdf = new SimpleDateFormat("dd");
date = sdf.format(date1);
} catch (ParseException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
protected void share() {
String shareBody = "Check out EmBazaar... http://www.code-brew.com/";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
activity.startActivity(Intent.createChooser(sharingIntent, "Share To:"));
}
}
feedlistcontents.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="@+id/ll_statusLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/feedstatus_layout"
android:visibility="gone" />
<include
android:id="@+id/rl_feedLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/feeditem_layout"
android:visibility="gone" />
<include
android:id="@+id/rl_feedEventLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/feed_event_layout"
android:visibility="gone" />
<include
android:id="@+id/ll_like"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/like_layout" />
</LinearLayout>
like_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_border_grey_bottom"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="4" >
<ImageView
android:id="@+id/iv_like"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="2dp"
android:src="@drawable/btn_like_normal" />
<ImageView
android:id="@+id/iv_comment"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="2dp"
android:src="@drawable/btn_message_tab_normal" />
<ImageView
android:id="@+id/iv_share"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="2dp"
android:src="@drawable/btn_share_normal" />
<ImageView
android:id="@+id/iv_dislike"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="2dp"
android:src="@drawable/btn_dislike_normal" />
</LinearLayout>