I have grid view , on which each item consists of few images and text . When it loads for the first time , everything is fine but if I scroll to the bottom and the go back to top some two images are gone from a item , and it goes randomly .
here is the code for Grid view
<GridView
android:id="#+id/testR_grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:columnWidth="#dimen/gridview_column_width"
android:horizontalSpacing="#dimen/grid_horizontal_spacing"
android:listSelector="#drawable/gridview_background"
android:numColumns="auto_fit"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:verticalScrollbarPosition="right"
android:verticalSpacing="#dimen/grid_vertical_spacing"
android:fastScrollEnabled="false"/>
Here the code for single item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_marginTop="5dp"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/blurry_shadow_rect">
<com.joooonho.SelectableRoundedImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/item_image"
android:layout_width="match_parent"
android:layout_height="#dimen/gridview_column_width"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="-5dp"
app:sriv_left_bottom_corner_radius="0dip"
app:sriv_left_top_corner_radius="4dip"
app:sriv_right_bottom_corner_radius="0dip"
app:sriv_right_top_corner_radius="4dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/item_image"
android:layout_marginBottom="5dp"
android:layout_marginLeft="2dp"
android:orientation="horizontal"
android:weightSum="100">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="35">
<TextView
android:id="#+id/item_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="start"
android:layout_marginBottom="5dp"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:text=""
android:textColor="#color/bodyText"
android:textSize="#dimen/GridHeader" />
<TextView
android:id="#+id/item_TestA_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/item_text"
android:layout_marginBottom="10dp"
android:alpha=".5"
android:ellipsize="end"
android:maxLines="1"
android:text=""
android:textColor="#color/bodyText"
android:textSize="#dimen/GridHeader2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:layout_weight="65">
<TextView
android:id="#+id/item_testR_free_text"
style="#style/textview_grid_free_banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:padding="2dp"
android:singleLine="true"
android:text=" FREE " />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/already_owned"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:singleLine="true"
android:layout_marginLeft="20dp"
android:layout_marginBottom="5dp"
android:visibility="gone"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_testR_bought_36dp" />
<ImageButton
android:id="#+id/item_testR_more_options"
android:layout_width="#dimen/image_button_more"
android:layout_height="#dimen/image_button_more"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/item_testR_free_text"
android:alpha=".5"
android:background="#drawable/imagebutton_background"
android:clickable="true"
android:focusable="false"
android:src="#drawable/ic_more_vert_black_24dp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
The elements are randomly missing are text view which id is item_testR_free_text and imageview which id is already_owned . One thing also to be noted the visibility of these two items are conditional .
Here is my code for adapter
public class TestRGridViewAdapter extends ArrayAdapter<TestR> {
Context context;
int layoutResourceId;
List<TestR> data = new ArrayList<TestR>();
RecordHolder holder = null;
//DiskCache imgCache;
TestA TestA;
TestR item;
FragmentActivity mFragmentActivity;
boolean is_local = false;
List<Track> trackList;
public TestR getItem() {
return item;
}
public void setItem(TestR item) {
this.item = item;
}
public TestRGridViewAdapter(Context context, int layoutResourceId,
List<TestR> data, FragmentActivity mFragmentActivity, boolean is_local) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.mFragmentActivity = mFragmentActivity;
// imgCache = Parameters.imgCache;
this.is_local = is_local;
}
public TestRGridViewAdapter(Context context, int layoutResourceId,
List<TestR> data, FragmentActivity mFragmentActivity) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.mFragmentActivity = mFragmentActivity;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
//LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = LayoutInflater.from(context).inflate(layoutResourceId, null);
//row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.item_testR_free_text = (TextView) row.findViewById(R.id.item_testR_free_text);
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.txtTestAName = (TextView) row.findViewById(R.id.item_TestA_name);
holder.imageItem = (SelectableRoundedImageView) row.findViewById(R.id.item_image);
holder.item_testR_more_options = (ImageButton) row.findViewById(R.id.item_testR_more_options);
holder.already_owned = (ImageView) row.findViewById(R.id.already_owned);
// holder.grid_swipe_refresh_layout = (SwipeRefreshLayout) row.findViewById(R.id.grid_swipe_refresh_layout);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
item = data.get(position);
holder.txtTitle.setText(item.getName());
// else
// holder.txtArtitName.setText("");
//holder.imageItem.setImageBitmap(item.getImage());
try {
if (item.getTestA_id() == null)
item = new SaveData(context).get_online_testR(item.getTestR_id());
TestA = Helper.getDaoSession(context).getTestADao().load(item.getTestA_id());
if (TestA == null) {
TestA = new SaveData(context).get_save_TestA(item.getTestA_id());
}
// if (TestA != null)
holder.txtTestAName.setText((TestA != null) ? TestA.getName() : "");
// else
// TestA = new SaveData(context).get_save_TestA(item.getTestA_id());
if (!is_local) {
if(!DBQuery.is_owner(context,item.getTestR_id())) {
Log.d("test","not owner - "+item.getName());
holder.item_testR_free_text.setText(
UXHelper.getPriceFromString(Parameters.price_type.equals("local_price") ?
item.getLocal_price().toString() : item.getPrice().toString()));
holder.already_owned.setVisibility(View.INVISIBLE);
holder.item_testR_more_options.setOnClickListener(new testR_popup_onClick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA));
}else {
Log.d("test","owner - "+item.getName());
holder.item_testR_free_text.setVisibility(View.INVISIBLE);
holder.already_owned.setVisibility(View.VISIBLE);
holder.item_testR_more_options.setOnClickListener(new testR_popup_onClick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA));
}
} else {
Log.d("test","local - "+item.getName());
holder.already_owned.setVisibility(View.INVISIBLE);
boolean synced = true;
trackList = new ArrayList<Track>();
List<Track> trackListTmp = new SaveData(context).get_tracks_local(item.getTestR_id());
boolean testR_owner = DBQuery.is_owner(context, trackListTmp.get(0).getTestR_id());
for (Track t : trackListTmp) {
boolean track_owner = DBQuery.is_owner(context, t.getTrack_id(), t.getTestR_id());
if (track_owner)
trackList.add(t);
if (testR_owner || track_owner) {
if (t.getSynced_dir() == null) {
synced = false;
// break;
} else if (!new File(t.getSynced_dir()).exists()) {
synced = false;
// break;
}
}
}
if (synced) {
Log.d("test","synched - "+item.getName());
holder.item_testR_free_text.setVisibility(View.VISIBLE);
holder.item_testR_free_text.setText("Synced");
} else {
Log.d("test","not synched - "+item.getName());
holder.item_testR_free_text.setVisibility(View.INVISIBLE);
holder.item_testR_more_options.setOnClickListener(
new testR_popup_downloaded_onCLick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA,
trackList.toArray(new Track[trackList.size()]), synced));
}
}
Target target = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
holder.imageItem.setImageBitmap(bitmap);
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
holder.imageItem.setImageResource(R.drawable.ic_example_36);
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
holder.imageItem.setImageResource(R.drawable.ic_example_36);
}
};
if (Parameters.mPicasso == null)
Parameters.mPicasso = new Picasso.Builder(context)
.build();
Parameters.mPicasso.load("http://" + context.getString(R.string.ip) + "/" +
context.getString(R.string.TestRsController) + "/" + context.getString(R.string.TESTR_THUMB_URL)
+ "/" + item.getTestR_id()+"/"+Parameters.dpi)
.placeholder(R.drawable.ic_example_36)
.error(R.drawable.ic_example_36)
.into(holder.imageItem);
} catch (Exception ex) {
new Logger(context).appendLog("Error in TestR grid view item " + ex.getMessage());
}
return row;
}
static class RecordHolder {
// SwipeRefreshLayout grid_swipe_refresh_layout;
TextView txtTitle;
TextView txtTestAName;
SelectableRoundedImageView imageItem;
TextView item_testR_free_text;
ImageButton item_testR_more_options;
ImageView already_owned;
}
}
Related
Please check following screenshot, I want to update imageview from parent recyclerview when user click on imageview from nested recyclerview.
I have taken two individual adapters for for parent & nested recyclerview.I am not able to do the functionality for updating image, kindly help.
Parent Recyclerview Adapter:
public class RecyclerViewDataAdapter extends RecyclerView.Adapter<RecyclerViewDataAdapter.ItemRowHolder> {
private ArrayList<PLDModel> dataList;
private Context mContext;
public RecyclerViewDataAdapter(Context context, ArrayList<PLDModel> dataList) {
this.dataList = dataList;
this.mContext = context;
}
#Override
public ItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_card_view, null);
ItemRowHolder mh = new ItemRowHolder(v);
return mh;
}
#Override
public void onBindViewHolder(ItemRowHolder itemRowHolder, int i) {
final String itemTitle = dataList.get(i).getTitle();
final String itemDescription = dataList.get(i).getDescription();
ArrayList<SmallImages> singleSectionItems = dataList.get(i).getSmallImages();
itemRowHolder.itemTitle.setText(Html.fromHtml("<b>" + itemTitle + " </b> " + itemDescription));
SectionListDataAdapter itemListDataAdapter = new SectionListDataAdapter(mContext, singleSectionItems);
itemRowHolder.recyclerSmallImageList.setHasFixedSize(true);
itemRowHolder.recyclerSmallImageList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
itemRowHolder.recyclerSmallImageList.setAdapter(itemListDataAdapter);
}
#Override
public int getItemCount() {
return (null != dataList ? dataList.size() : 0);
}
public class ItemRowHolder extends RecyclerView.ViewHolder {
protected TextView itemTitle, expandImage;
protected ImageView bookmarkImage,largeImage;
protected RecyclerView recyclerSmallImageList;
protected Button btnMore;
public ItemRowHolder(View view) {
super(view);
this.itemTitle = (TextView) view.findViewById(R.id.title);
this.bookmarkImage = (ImageView) view.findViewById(R.id.bookmark);
this.largeImage = (ImageView) view.findViewById(R.id.large_image);
this.expandImage = (TextView) view.findViewById(R.id.expand);
this.recyclerSmallImageList = (RecyclerView) view.findViewById(R.id.recycler_small_image_list);
}
}
}
Nested Recyclerview Adapter:
public class SectionListDataAdapter extends RecyclerView.Adapter<SectionListDataAdapter.SingleItemRowHolder> {
private ArrayList<SmallImages> itemsList;
private Context mContext;
public SectionListDataAdapter(Context context, ArrayList<SmallImages> itemsList) {
this.itemsList = itemsList;
this.mContext = context;
}
#Override
public SingleItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.small_images_view, null);
SingleItemRowHolder mh = new SingleItemRowHolder(v);
return mh;
}
#Override
public void onBindViewHolder(SingleItemRowHolder holder, int i) {
SmallImages singleItem = itemsList.get(i);
}
#Override
public int getItemCount() {
return (null != itemsList ? itemsList.size() : 0);
}
public class SingleItemRowHolder extends RecyclerView.ViewHolder {
protected ImageView itemImage;
public SingleItemRowHolder(View view) {
super(view);
//this.tvTitle = (TextView) view.findViewById(R.id.tvTitle);
this.itemImage = (ImageView) view.findViewById(R.id.item_small_image);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(v.getContext(), tvTitle.getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
Using two Recyclerview will be hard to control rather than use a Single adapter and control everything from there.I have just worked on this type of thing that's why I am posting my code there may be some unwanted code which u may need.
/////Adapter class
public class AdapterTodayTrip extends RecyclerView.Adapter<AdapterTodayTrip.VHItem> {
private Context mContext;
private int rowLayout;
private List<ModelRouteDetailsUp> dataMembers;
private ArrayList<ModelRouteDetailsUp> arraylist;
private ArrayList<ModelKidDetailsUp> arraylist_kids;
List<String> wordList = new ArrayList<>();
Random rnd = new Random();
int randomNumberFromArray;
private ModelRouteDetailsUp personaldata;
private ProgressDialog pDialog;
private ConnectionDetector cd;
String img_baseurl = "";
String item = "";
public AdapterTodayTrip(Context mcontext, int rowLayout, List<ModelRouteDetailsUp> tripList, String flag, String img_baseurl) {
this.mContext = mcontext;
this.rowLayout = rowLayout;
this.dataMembers = tripList;
wordList.clear();
this.img_baseurl = img_baseurl;
arraylist = new ArrayList<>();
arraylist_kids = new ArrayList<>();
arraylist.addAll(dataMembers);
cd = new ConnectionDetector(mcontext);
pDialog = KPUtils.initializeProgressDialog(mcontext);
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public AdapterTodayTrip.VHItem onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
return new AdapterTodayTrip.VHItem(v);
}
#Override
public int getItemCount() {
return dataMembers.size();
}
#Override
public void onBindViewHolder(final AdapterTodayTrip.VHItem viewHolder, final int position) {
viewHolder.setIsRecyclable(false);
try {
personaldata = dataMembers.get(position);
if (!KPHashmapUtils.m_ride_route_details_up.get(position).getKidpool_route_id().isEmpty() && !KPHashmapUtils.m_ride_route_details_up.get(position).getKidpool_route_id().equals("null")) {
viewHolder.tv_trip_id.setText("#" + KPHashmapUtils.m_ride_route_details_up.get(position).getKidpool_route_id());
}
****///////inflate the child list here and onclick on the image below in the inflated view it will load the image in the main view****
if (personaldata.getKidlist().size() > 0) {
viewHolder.linear_childview.setVisibility(View.VISIBLE);
viewHolder.tv_total_count.setText(""+personaldata.getKidlist().size());
viewHolder.id_gallery.removeAllViews();
LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
buttonLayoutParams.setMargins(0, 0, 8, 0);
LayoutInflater layoutInflater = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0; i < personaldata.getKidlist().size(); i++) {
View view = layoutInflater.inflate(R.layout.view_child_list, null);
view.setLayoutParams(buttonLayoutParams);
RelativeLayout rl_txt = (RelativeLayout)view.findViewById(R.id.rl_txt);
RelativeLayout rl_img = (RelativeLayout)view.findViewById(R.id.rl_img);
TextView tv_count = (TextView)view.findViewById(R.id.tv_count);
com.app.kidpooldriver.helper.CircularTextView tv_name = (com.app.kidpooldriver.helper.CircularTextView)view.findViewById(R.id.tv_name);
final CircleImageView iv_circular = (CircleImageView)view.findViewById(R.id.iv_circular);
int count = i + 1;
String count1 = "0";
if (count <= 10) {
count1 = "0" + count;
}
tv_count.setText(String.valueOf(count1));
viewHolder.id_gallery.addView(view);
final String baseurl = img_baseurl + "" + personaldata.getKidlist().get(i).getKid_image();
**/////set the url of the small image in the tag here**
if(!baseurl.isEmpty()) {
iv_circular.setTag(baseurl);
}
if (!personaldata.getKidlist().get(i).getKid_image().isEmpty()) {
GradientDrawable bgShape = (GradientDrawable) rl_img.getBackground();
bgShape.setColor(Color.parseColor("#A6b1a7a6"));
rl_txt.setVisibility(View.GONE);
//rl_img.setVisibility(View.VISIBLE);
tv_name.setVisibility(View.GONE);
Log.d("aimg_baseurl", baseurl);
try {
Picasso.with(mContext)
.load(baseurl)
.resize(60,60)
.centerCrop()
.into(iv_circular);
iv_circular.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String url=iv_circular.getTag().toString().trim();
if(!url.isEmpty())
KPUtils.showToastShort(mContext,url);
Picasso.with(mContext)
.load(url)
.resize(60,60)
.centerCrop()
.into(viewHolder.img_child);
}
});
} catch (Exception e) {
}
} else {
}
}
}else{
viewHolder.linear_childview.setVisibility(View.GONE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
class VHItem extends RecyclerView.ViewHolder {
CardView cv_members;
ImageView img_child;
TextView tv_trip_id, tv_trip_status, tv_vehicle_number, tv_trip_start_time, tv_trip_end_time, tv_trip_way, tv_total_count;
LinearLayout id_gallery,linear_childview;
public VHItem(View itemView) {
super(itemView);
img_child= (ImageView) itemView.findViewById(R.id.img_child);
cv_members = (CardView) itemView.findViewById(R.id.cv_members);
tv_trip_id = (TextView) itemView.findViewById(R.id.tv_trip_id);
tv_trip_status = (TextView) itemView.findViewById(R.id.tv_trip_status);
tv_vehicle_number = (TextView) itemView.findViewById(R.id.tv_vehicle_number);
tv_trip_start_time = (TextView) itemView.findViewById(R.id.tv_trip_start_time);
tv_trip_end_time = (TextView) itemView.findViewById(R.id.tv_trip_end_time);
tv_trip_way = (TextView) itemView.findViewById(R.id.tv_trip_way);
tv_total_count = (TextView) itemView.findViewById(R.id.tv_total_count);
id_gallery = (LinearLayout) itemView.findViewById(R.id.id_gallery);
linear_childview= (LinearLayout) itemView.findViewById(R.id.linear_childview);
}
}
}
/////////////////////////// this layout is inflated in every row
view_child_list
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/iv_circular"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#mipmap/ic_launcher"
app:civ_border_color="#d27959"
app:civ_border_width="1dp" />
<RelativeLayout
android:id="#+id/rl_txt"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:background="#drawable/gy_ring_circular"
android:gravity="center"
android:visibility="gone">
<com.app.kidpooldriver.helper.CircularTextView
android:id="#+id/tv_name"
fontPath="fonts/Poppins-Bold.ttf"
android:layout_width="70dp"
android:layout_height="70dp"
android:gravity="center"
android:text="01"
android:textColor="#color/white"
android:textSize="35sp"
tools:ignore="MissingPrefix" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#drawable/gy_ring_circular"
android:gravity="center"
android:visibility="visible">
<TextView
android:id="#+id/tv_count"
fontPath="fonts/Poppins-Bold.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="01"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#ffffff"
android:textStyle="bold"
tools:ignore="MissingPrefix" />
</RelativeLayout>
</FrameLayout>
///// this is the mianlayout which is inflated.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cv_members"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/card_margin"
android:elevation="#dimen/elevation"
card_view:cardCornerRadius="5dp">
<LinearLayout
android:id="#+id/main_body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:layout_marginTop="#dimen/fifteen"
android:orientation="horizontal"
android:paddingLeft="#dimen/ten">
<TextView
android:id="#+id/tv_trip_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#KD09201701"
android:textColor="#color/colorPrimary"
android:textSize="#dimen/twenty"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_trip_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/light_green"
android:gravity="center"
android:padding="5dp"
android:text="In Progress"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#color/black" />
</LinearLayout>
<TextView
android:id="#+id/tv_vehicle_number"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:text="Route 26U-26D"
android:visibility="gone"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#color/route_textcolor" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_trip_start_time"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/five"
android:paddingLeft="20dp"
android:text="06:30am"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/grey_textcolor" />
<TextView
android:id="#+id/tv_trip_end_time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/five"
android:paddingLeft="20dp"
android:text="08:30am"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/grey_textcolor"
android:visibility="gone" />
</LinearLayout>
<TextView
android:id="#+id/tv_trip_way"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/five"
android:paddingLeft="20dp"
android:visibility="gone"
android:paddingRight="20dp"
android:text="Chingrighata > NiccoPark > SDF > College More > DLF 1 > Eco Space"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#color/grey_textcolor"
android:textStyle="normal" />
<ImageView
android:id="#+id/img_child"
android:layout_width="200dp"
android:layout_gravity="center"
android:layout_height="200dp" />
<LinearLayout
android:id="#+id/linear_childview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/fifteen"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:scrollbars="none">
<LinearLayout
android:id="#+id/id_gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" />
</HorizontalScrollView>
<LinearLayout
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#drawable/ly_ring_circular"
android:gravity="center_vertical">
<TextView
android:id="#+id/tv_total_count"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:ignore="MissingPrefix"
fontPath="fonts/Poppins-Bold.ttf"
android:text="+20"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
/////POJO CLASS &json parsing & Adapter /////
public class ModelRouteDetailsUp {
String city_id;
String area_name;
String area_status;
String is_active;
String areas;
private ArrayList<ModelKidDetailsUp> kidlist;
///////this is the kid list
public ArrayList<ModelKidDetailsUp> getKidlist() {
return kidlist;
}
public void setKidlist(ArrayList<ModelKidDetailsUp> kidlist) {
this.kidlist = kidlist;
}
}
**///json parsing.......**
public boolean addRideDetails(JSONObject jsonObject) {
Boolean flag = false;
String isstatus = "";
if (jsonObject != null && jsonObject.length() > 0) {
try {
JSONArray mainArray = jsonObject.getJSONArray("schedules");
for (int i = 0; i < mainArray.length(); i++) {
ModelRouteDetailsUp modelRouteDetails = new ModelRouteDetailsUp();
JSONObject c = mainArray.getJSONObject(i);
////// For Route Details //////
JSONObject route_details = c.getJSONObject("route_details");
modelRouteDetails.setDs_id(route_details.optString("ds_id"));
modelRouteDetails.setDriver_id(route_details.optString("driver_id"));
modelRouteDetails.setTrip_id(route_details.optString("trip_id"));
modelRouteDetails.setRoute_id(route_details.optString("route_id"));
modelRouteDetails.setVehicle_id(route_details.optString("vehicle_id"));
modelRouteDetails.setStart_time(route_details.optString("start_time"));
modelRouteDetails.setEnd_time(route_details.optString("end_time"));
////// For Allotted Kids //////
JSONArray kidArray = c.getJSONArray("alloted_kids");
ArrayList<ModelKidDetailsUp> genre = new ArrayList<ModelKidDetailsUp>();
if (kidArray.length() > 0) {
for (int j = 0; j < kidArray.length(); j++) {
ModelKidDetailsUp kidDetailsUp = new ModelKidDetailsUp();
JSONObject kidObject = kidArray.getJSONObject(j);
kidDetailsUp.setKid_name(kidObject.getString("kid_name"));
kidDetailsUp.setKid_gender(kidObject.getString("kid_gender"));
kidDetailsUp.setKid_dob(kidObject.getString("kid_dob"));
kidDetailsUp.setKid_image(kidObject.getString("kid_image"));
genre.add(kidDetailsUp);
}
}
///////add the kidlist here
modelRouteDetails.setKidlist(genre);
////main array contains all the data i.e route details and kidlist for every row
KPHashmapUtils.m_ride_route_details_up.add(modelRouteDetails);
//}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return flag;
}
**/////adapter callfrom class**
private void showData() {
if (KPHashmapUtils.m_ride_route_details_up.size() > 0){
adapterTodayTrip = new AdapterTodayTrip(mContext, R.layout.list_item_todaytrip, KPHashmapUtils.m_ride_route_details_up, "TodayTrip",img_baseurl);
rv_trip_list.setAdapter(adapterTodayTrip);
}else {
tv_msg.setVisibility(View.VISIBLE);
}
}
Generally, the solution is to pass custom interface listener into the nested adapter and than the nested adapter will report any time one of his item clicked.
1.
You can create interface like:
public interface INestedClicked {
onNestedItemClicked(Drawable drawble)
}
2.
Pass in the constructor of SectionListDataAdapter a INestedClicked:
SectionListDataAdapter itemListDataAdapter = newSectionListDataAdapter(mContext, singleSectionItems, new INestedClicked() {
#Override
void onNestedItemClicked(Drawable drawble) {
// Do whatever you need after the click, you get the drawable here
}
});
In the constructor of SectionListDataAdapter save the instance of the listener as adapter parameter
private INestedClicked listener;
4.
When nested item clicked report the listener:
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(listener != null){
listener.onNestedItemClicked(imageView.getDrawable());
}
}
I done video playing inside recyclerview with cardview using sdcard path location. Also check sdcard not available then fetch recorded videos from internal memory. Its perfectly working in Lava iris x8 device, but in Samsung J5 and Samsung Note 2 only odd numbers(1,3,5,7) videos are playing not even(2,4,6,8) videos are playing and getting dialog like "Can't play this video" when scrolling and getting position of even(2,4,6,8) numbers of video. I am not able to know what is the problem? Below is my whole code about display and play video inside recyclerview and cardview in android.
display_video.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/mRelative_background"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#6FC298">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<RelativeLayout
android:id="#+id/mRelativeClick"
android:layout_width="50dp"
android:layout_height="30dp"
android:gravity="left">
<ImageView
android:id="#+id/mImage_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#mipmap/icon_back"></ImageView>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="My Challenge"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="italic" />
<ImageView
android:id="#+id/mImageView_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#mipmap/icon_setting"></ImageView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/mRelative_circular_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="65dp">
<ImageView
android:id="#+id/mImageView_color1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:visibility="invisible"
android:layout_marginLeft="10dp"
android:src="#mipmap/color1"/>
<ImageView
android:id="#+id/mImageView_color2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color1"
android:src="#mipmap/color2"/>
<ImageView
android:id="#+id/mImageView_color3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color2"
android:src="#mipmap/color3"/>
<app.stakes.CircularImageView
android:id="#+id/mcircularImage"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerInParent="true"
android:background="#mipmap/camera_icon" />
<ImageView
android:id="#+id/mImageView_color4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mcircularImage"
android:src="#mipmap/color4"/>
<ImageView
android:id="#+id/mImageView_color5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color4"
android:src="#mipmap/color5"/>
<ImageView
android:id="#+id/mImageView_color6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/mImageView_color5"
android:src="#mipmap/color6"/>
</RelativeLayout>
<TextView
android:id="#+id/mTextViewUsername_VideoList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mRelative_circular_image"
android:layout_centerInParent="true"
android:layout_marginTop="25dp"
android:text="Text"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="italic" />
<ImageView
android:id="#+id/mImageView_color_table"
android:src="#mipmap/color_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mRelative_circular_image"
android:layout_marginTop="25dp"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/mRelativeTab"
android:layout_below="#+id/mRelative_background"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/mImageViewtab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/list"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:id="#+id/mImageViewtab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/view"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp" />
<ImageView
android:id="#+id/mImageViewtab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/showbook"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="40dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/mRelativeTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:scrollbars="vertical" />
</RelativeLayout>
</RelativeLayout>
cardview1.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="5dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:background="#FFFFFF"
android:id="#+id/mRelativeMain"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--<ImageView
android:id="#+id/iconId"
android:layout_width="300dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"/>-->
<app.stakes.CircularImageView
android:id="#+id/circleImageview"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#mipmap/camera_icon" />
<TextView
android:id="#+id/tvVersionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/circleImageview"
android:layout_marginLeft="5dp"
android:text="Auther"
android:textColor="#android:color/black"
android:textSize="7sp" />
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/circleImageview"
android:layout_marginLeft="70dp"
android:textColor="#android:color/black"
android:textSize="10sp" />
<ImageView
android:id="#+id/mImageview_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_toLeftOf="#+id/tvSec"
android:src="#mipmap/timing"/>
<TextView
android:id="#+id/tvSec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="35dp"
android:text="Lollipop"
android:textColor="#android:color/black"
android:textSize="5sp" />
<FrameLayout
android:id="#+id/video_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/circleImageview">
<com.sprylab.android.widget.TextureVideoView
android:id="#+id/mvideoView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal|center_vertical"
/>
<ImageView
android:id="#+id/mImageview_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:src="#mipmap/play" />
<ImageView
android:id="#+id/mImageView_fav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/mImageview_play"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="40dp"
android:layout_marginTop="130dp"
android:src="#mipmap/bookmark_video" />
<ImageView
android:id="#+id/mImageView_share"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#+id/mImageview_play"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="40dp"
android:layout_marginTop="130dp"
android:src="#mipmap/sharevideo" />
<!--</RelativeLayout>-->
</FrameLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
Display_Video1.java
public class Display_Video1 extends ActionBarActivity {
public RecyclerView recyclerView;
private ArrayList<FeddProperties> os_versions;
private Adapter mAdapter;
private Adapter fav_video_adapter;
CircularImageView mcircularImage;
static DisplayMetrics dm;
static MediaController media_Controller;
RelativeLayout mRelativeClick;
static boolean isViewWithCatalog;
RelativeLayout mRelative_background;
static File OldFile;
static String[] fileList = null;
static String[] fileListOld = null;
/*static String FILE_PATH = newFile.getAbsolutePath();*/
static String FILEPATH_OLD;
static String videoOldFilePath;
static String replaceOldString;
String MiME_TYPE = "video/mp4";
static String videoFilePath;
static String replaceStr;
static String[] fav_video_list = null;
CallbackManager callbackManager;
public static String facebook_user_id;
public static String username;
Boolean isSDPresent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.display_video);
isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
if(isSDPresent) {
OldFile = new File(Environment.getExternalStorageDirectory(), "/Stakes_Download");
MEDIA_PATHOLD = new String(OldFile.getAbsolutePath());
FILEPATH_OLD = OldFile.getAbsolutePath();
}
else{
OldFile = new File(this.getFilesDir(), "Stakes_Download");
MEDIA_PATHOLD = new String(OldFile.getAbsolutePath());
FILEPATH_OLD = OldFile.getAbsolutePath();
}
recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
os_versions = new ArrayList<FeddProperties>();
if (fileList != null) {
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileList.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileList), Toast.LENGTH_LONG).show();
}
}
}
if (fileListOld != null) {
for (int i = 0; i < fileListOld.length; i++) {
if (fileListOld[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileListOld.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileListOld), Toast.LENGTH_LONG).show();
}
}
}
recyclerView.setHasFixedSize(true);
// ListView
recyclerView.setLayoutManager(new LinearLayoutManager(Display_Video1.this));
// create an Object for Adapter
if (fileList != null) {
mAdapter = new CardViewDataAdapter(Display_Video1.this, fileList);
// set the adapter object to the Recyclerview
recyclerView.setAdapter(mAdapter);
} else {
/*Toast.makeText(getApplicationContext(),"No File Exist",Toast.LENGTH_LONG).show();*/
}
updateSongList();
updateSongListOld();
initContrls();
}
public void updateSongList() {
File videoFiles = new File(MEDIA_PATHOLD);
Log.d("**Value of videoFiles**", videoFiles.toString());
if (videoFiles.isDirectory()) {
fileList = videoFiles.list();
}
if (fileList == null) {
System.out.println("File doesnot exit");
Toast.makeText(this, "There is no file", Toast.LENGTH_SHORT).show();
} else {
System.out.println("fileList****************" + fileList);
for (int i = 0; i < fileList.length; i++) {
Log.e("Video:" + i + " File name", fileList[i]);
}
}
}
public void updateSongListOld() {
File videoFiles = new File(MEDIA_PATHOLD);
Log.d("**Value of videoFiles**", videoFiles.toString());
if (videoFiles.isDirectory()) {
fileListOld = videoFiles.list();
}
if (fileListOld == null) {
System.out.println("File doesnot exit");
Toast.makeText(this, "There is no file", Toast.LENGTH_SHORT).show();
} else {
System.out.println("fileList****************" + fileListOld);
for (int i = 0; i < fileListOld.length; i++) {
Log.e("Video:" + i + " File name", fileListOld[i]);
}
}
}
private void initContrls() {
recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
os_versions = new ArrayList<FeddProperties>();
if (fileList != null) {
/*gridView.setAdapter(new ImageAdapter(this, fileList));*/
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileList.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileList), Toast.LENGTH_LONG).show();
/* FeddProperties feed = new FeddProperties();
feed.setTitle(fileList[i]);
*//*feed.setThumbnail(icons[i]);*//*
os_versions.add(feed);*/
}
}
}
if (fileListOld != null) {
/*gridView.setAdapter(new ImageAdapter(this, fileList));*/
for (int i = 0; i < fileListOld.length; i++) {
if (fileListOld[i].length() == 0) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(fileListOld.length);
Toast.makeText(getApplicationContext(), "File Zero: " + Arrays.toString(fileListOld), Toast.LENGTH_LONG).show();
/* FeddProperties feed = new FeddProperties();
feed.setTitle(fileList[i]);
*//*feed.setThumbnail(icons[i]);*//*
os_versions.add(feed);*/
}
}
}
recyclerView.setHasFixedSize(true);
// ListView
recyclerView.setLayoutManager(new LinearLayoutManager(this));
//Grid View
/* recyclerView.setLayoutManager(new GridLayoutManager(this,2,1,false));*/
//StaggeredGridView
/*recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,1));*/
// create an Object for Adapter
if (fileList != null) {
mAdapter = new CardViewDataAdapter(Display_Video1.this, fileList);
// set the adapter object to the Recyclerview
recyclerView.setAdapter(mAdapter);
} else {
/*Toast.makeText(getApplicationContext(),"No File Exist",Toast.LENGTH_LONG).show();*/
}
recyclerView.addOnItemTouchListener(new CardViewDataAdapter(Display_Video1.this, new CardViewDataAdapter.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
}
}));
}
Recyclerview Adapter
public static class CardViewDataAdapter extends Adapter<CardViewDataAdapter.ViewHolder> implements OnItemTouchListener {
private ArrayList<FeddProperties> dataSet;
private OnItemClickListener mListener;
GestureDetector mGestureDetector;
private Context context;
private String[] VideoValues;
private int position = 0;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
public CardViewDataAdapter(Context context, String[] VideoValues) {
/*dataSet = os_versions;*/
this.context = context;
this.VideoValues = VideoValues;
}
public CardViewDataAdapter(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
#Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
// create a new view
View itemLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.card_view1, null);
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
videoFilePath = FILEPATH_OLD + "/" + fileList[i];
Toast.makeText(context,"Path: "+videoFilePath,Toast.LENGTH_LONG).show();
viewHolder.tvVersionName.setText(fileList[i]);
System.out
.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>> file path>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+ fileList[i]);
viewHolder.mvideoView.setVideoPath(videoFilePath);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(context, Uri.parse(videoFilePath));
final String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInMillisec = Long.parseLong(time);
final long duration = timeInMillisec / 1000;
long hours = duration / 3600;
long minutes = (duration - hours * 3600) / 60;
final long seconds = duration - (hours * 3600 + minutes * 60);
viewHolder.tvSec.setText(String.valueOf(seconds) + "s");
viewHolder.mImageview_play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (viewHolder.mvideoView!= null) {
if (viewHolder.mvideoView.isPlaying()) {
viewHolder.mvideoView.pause();
viewHolder.mImageview_play.setImageResource(R.mipmap.play);
} else {
viewHolder.mvideoView.start();
viewHolder.mImageview_play.setImageResource(R.mipmap.play_click);
}
}
viewHolder.mvideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
viewHolder.mImageview_play.setImageResource(R.mipmap.play);
}
});
}
});
viewHolder.str = fileList;
}
#Override
public int getItemCount() {
return VideoValues.length;
}
#Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent e) {
View childView = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, recyclerView.getChildAdapterPosition(childView));
}
return false;
}
#Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
}
#Override
public void onRequestDisallowInterceptTouchEvent(boolean b) {
}
// inner class to hold a reference to each item of RecyclerView
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView tvVersionName;
public TextView tvTitle;
public TextView tvSec;
/*public ImageView iconView;*/
/*public RelativeLayout mvideoView;*/
public TextureVideoView mvideoView;
public ImageView mImageview_play;
public CircularImageView circleImageview;
public ImageView mImageView_fav;
public ImageView mImageView_share;
public FeddProperties feed;
public String[] str;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
tvVersionName = (TextView) itemLayoutView
.findViewById(R.id.tvVersionName);
/*iconView = (ImageView) itemLayoutView
.findViewById(R.id.iconId);*/
tvSec = (TextView) itemLayoutView.findViewById(R.id.tvSec);
tvTitle = (TextView) itemLayoutView.findViewById(R.id.tvTitle);
mvideoView = (TextureVideoView) itemLayoutView.findViewById(R.id.mvideoView);
mImageview_play = (ImageView) itemLayoutView.findViewById(R.id.mImageview_play);
}
}
}
I was stuck all day. Couldn't find my mistake.
I created a Custom ListView, and I just want to be able to click on it to launch a new intent in HourListView.
public class CustomList extends ArrayAdapter<String> {
private final ArrayList<String> hourList;
private final Activity context;
public CustomList(Activity context,
ArrayList<String> hourList) {
super(context, R.layout.hour_list_adapter, hourList);
this.context = context;
this.hourList = hourList;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
View rowView = view;
ViewHolder viewHolder = null;
// LayoutInflater inflater = context.getLayoutInflater();
// View rowView= inflater.inflate(R.layout.hour_list_adapter, parent, false);
if(rowView == null)
{
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.hour_list_adapter, parent, false);
viewHolder = new ViewHolder();
viewHolder.type_frequenceTV = (TextView) rowView.findViewById(R.id.type_frequence);
viewHolder.dateTV = (TextView) rowView.findViewById(R.id.date);
viewHolder.dureeTV = (TextView) rowView.findViewById(R.id.duree);
viewHolder.commentaireTV = (TextView) rowView.findViewById(R.id.commentaire);
viewHolder.simuIV = (ImageView) rowView.findViewById(R.id.simulateur);
viewHolder.doubleIV = (ImageView) rowView.findViewById(R.id.doubleFrequence);
rowView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder)rowView.getTag();
}
viewHolder.type_frequenceTV.setText(HourListActivity.hourObjects.get(position).get("type_frequence").toString());
viewHolder.dureeTV.setText(HourListActivity.hourObjects.get(position).get("duree").toString());
viewHolder.commentaireTV.setText(HourListActivity.hourObjects.get(position).get("comment").toString());
Date dateAndTime = (Date) HourListActivity.hourObjects.get(position).get("date");
SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yy à HH:mm");
String formatted = format1.format(dateAndTime.getTime());
viewHolder.dateTV.setText("Le " + formatted);
if ((Boolean) HourListActivity.hourObjects.get(position).get("double"))
{
viewHolder.doubleIV.setVisibility(View.VISIBLE);
}
else
{
viewHolder.doubleIV.setVisibility(View.GONE);
}
if ((Boolean) HourListActivity.hourObjects.get(position).get("simulateur"))
{
viewHolder.simuIV.setVisibility(View.VISIBLE);
}
else
{
viewHolder.simuIV.setVisibility(View.GONE);
}
rowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
return rowView;
}
static class ViewHolder
{
TextView type_frequenceTV;
TextView dateTV ;
TextView dureeTV ;
TextView commentaireTV ;
ImageView simuIV ;
ImageView doubleIV ;
}
}
Then this is the HourListActivity where I want to be able to click.
public class HourListActivity extends AppCompatActivity {
//ArrayAdapter<String> arrayAdapter;
CustomList adapter;
ListView hourListView;
static ArrayList<String> hourList;
static ArrayList<String> hourListID;
static ArrayList<ParseObject> hourObjects = new ArrayList<ParseObject>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hour_list);
hourList = new ArrayList<>();
hourListID = new ArrayList<>();
hourListView = (ListView) findViewById(R.id.listView);
adapter = new CustomList(HourListActivity.this,hourList);
//arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, hourList);
hourListView.setAdapter(adapter);
hourListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("CLIC !!!!!!!!!!!!!!!!!!!!!");
ParseQuery<ParseObject> query = ParseQuery.getQuery("Frequence");
query.getInBackground(hourListID.get(position), new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), ModifyHourActivity.class);
intent.putExtra("objectID", object.getObjectId());
startActivity(intent);
} else {
// something went wrong
}
}
});
}
});
ParseQuery<ParseObject> query = ParseQuery.getQuery("Frequence");
query.whereEqualTo("username", ParseUser.getCurrentUser().getUsername());
System.out.println("username: " + ParseUser.getCurrentUser().getUsername() );
query.orderByDescending("date");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null)
{
if (objects.size() > 0)
{
hourObjects.clear();
for (ParseObject frequence : objects)
{
String result = "";
result += frequence.get("date") + " - "
+ frequence.get("type_frequence") + " - "
+ frequence.get("duree") + " - "
+ frequence.get("comment") + " - "
+ frequence.get("double") + " - "
+ frequence.get("simulateur") + " - ";
System.out.println("Résultat : " + result);
hourList.add(result.toString());
hourListID.add(frequence.getObjectId());
ParseObject newHour = new ParseObject("Temp");
newHour.put("username", frequence.get("username"));
// newHour.put("id", frequence.get("objectId"));
newHour.put("type_frequence", frequence.get("type_frequence"));
newHour.put("date", frequence.get("date"));
newHour.put("duree", frequence.get("duree"));
newHour.put("comment", frequence.get("comment"));
newHour.put("double", frequence.get("double"));
newHour.put("simulateur", frequence.get("simulateur"));
hourObjects.add(newHour);
}
Toast.makeText(HourListActivity.this, "Liste des heures récupérée !",
Toast.LENGTH_LONG).show();
adapter.notifyDataSetChanged();
}
}
else
{
}
}
});
A lastly my xml file for the Custom View:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:layout_margin="5dp"
>
<TextView
android:id="#+id/type_frequence"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:gravity="center"
android:text="DEP S"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/buttonTextColor"
android:paddingLeft="10dp"
android:paddingRight="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal">
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:textSize="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="12 avril 2016 - 08:00"
android:layout_marginLeft="5dp"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:id="#+id/duree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:text="1.00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/buttonTextColor"
android:layout_alignParentEnd="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal">
<TextView
android:id="#+id/commentaire"
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:text="Commentaire"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
<ImageView
android:id="#+id/doubleFrequence"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_column="1"
android:src="#drawable/double_96" />
<ImageView
android:id="#+id/simulateur"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_column="1"
android:src="#drawable/simu_96"
android:layout_toStartOf="#+id/doubleFrequence" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thanks in advance for any help ! :)
What happens when you delete this part in your adapter ?
rowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
I guess what happens is that the view are created after you have defined the ItemClickListener in your activity, resulting in the ClickListener being overriden at run time by the one in your adapter.
As far as I am concerned if you are facing an error with setOnClickListener you can try this
Go to Tools--> sync with Gradle.
It helped me when I was stucked with the intent problem!
I implemented a custom listView as seen here:
http://www.tutecentral.com/android-custom-navigation-drawer/ but I can't get a correct height for my items in the list. Both header and section layout are way too large (height).
Here is my xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/profileLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="0dp"
>
<com.facebook.widget.ProfilePictureView
android:id="#+id/drawer_profilePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
/>
<TextView
android:id="#+id/drawer_profileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="0dp">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:id="#+id/button_logout"
android:text="Logout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/sectionLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
>
<TextView
android:id="#+id/drawer_sectionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:layout_marginTop="0dp"
>
<TextView
android:id="#+id/drawer_headerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:background="#DADADC" ></View>
</LinearLayout>
Any suggestion ?
[EDIT] Here is my customDrawerAdapter getview code:
public class CustomDrawerAdapter extends ArrayAdapter<DrawerItem> {
private final JSONObject userProfile;
Context context;
List<DrawerItem> drawerItemList;
int layoutResID;
public CustomDrawerAdapter(Context context, int layoutResourceID,
List<DrawerItem> listItems, JSONObject userProfile) {
super(context, layoutResourceID, listItems);
this.context = context;
this.drawerItemList = listItems;
this.layoutResID = layoutResourceID;
this.userProfile = userProfile;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
DrawerItemHolder drawerHolder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
drawerHolder = new DrawerItemHolder();
view = inflater.inflate(layoutResID, parent, false);
drawerHolder.profileName = (TextView) view
.findViewById(R.id.drawer_profileName);
drawerHolder.profilePicture = (ProfilePictureView) view.findViewById(R.id.drawer_profilePicture);
drawerHolder.sectionName = (TextView) view.findViewById(R.id.drawer_sectionName);
drawerHolder.headerName = (TextView) view.findViewById(R.id.drawer_headerName);
drawerHolder.buttonLogout = (Button) view.findViewById(R.id.button_logout);
drawerHolder.buttonLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getContext(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.getContext().startActivity(intent);
}
});
drawerHolder.profileLayout = (LinearLayout) view.findViewById(R.id.profileLayout);
drawerHolder.sectionLayout = (LinearLayout) view.findViewById(R.id.sectionLayout);
drawerHolder.headerLayout = (LinearLayout) view.findViewById(R.id.headerLayout);
view.setTag(drawerHolder);
} else {
drawerHolder = (DrawerItemHolder) view.getTag();
}
DrawerItem dItem = this.drawerItemList.get(position);
if (dItem.isHeader()) {
drawerHolder.profileLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.sectionLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.headerLayout.setVisibility(LinearLayout.VISIBLE);
drawerHolder.headerName.setText(dItem.getHeaderName());
} else if (dItem.getProfilePicture() == 0){
drawerHolder.profileLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.sectionLayout.setVisibility(LinearLayout.VISIBLE);
drawerHolder.headerLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.sectionName.setText(dItem.getSectionName());
} else {
drawerHolder.profileLayout.setVisibility(LinearLayout.VISIBLE);
drawerHolder.sectionLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.headerLayout.setVisibility(LinearLayout.INVISIBLE);
try {
if (userProfile.getString("facebookId") != null) {
String facebookId = userProfile.get("facebookId")
.toString();
drawerHolder.profilePicture.setProfileId(facebookId);
} else {
// Show the default, blank user profile picture
drawerHolder.profilePicture.setProfileId(null);
}
if (userProfile.getString("name") != null) {
drawerHolder.profileName.setText(userProfile.getString("name"));
} else {
drawerHolder.profileName.setText("");
}
} catch (JSONException e) {
Log.d(CarpoolMeApp.TAG,
"Error parsing saved user data.");
}
}
return view;
}
You can just set the height manually for both the headerName and the sectionName Textviews
android:layout_height="2dp"
like you did with the View in your headerLayout
You can specify layouts gravities, it is most possible reason of issue (too much height).
Also you can use LinearLayout as root layout instead of RelativeLayout.
If the exact height needed, specify it in the layout_height parameter.
I'm now implementing a custom ListView. When I tried to change the TextView that is located in CustomAdaper.xml from MainActivity. It show NullPointerException. Isn't it possible to do like this . Help me finding it Please . I get so confused .
Below is my MainActivity.java Code :
setContentView(R.layout.activity_main);
txt_Position = (TextView)findViewById(R.id.txtposition);//still ok
txt_memberName = (TextView)findViewById(R.id.txtmemberName);// still ok
LayoutParams params = (LayoutParams) layout_Date.getLayoutParams();
LayoutParams params1 = (LayoutParams) layout_List.getLayoutParams();
LayoutParams params2 = (LayoutParams) layout_Rotation.getLayoutParams();
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Toast.makeText(this, "Large", Toast.LENGTH_LONG).show();
params.height = 100;
params1.height = 330 ;
params2.height = 200;
txt_Position.setTextSize((float)18.0); //locate in CustomAdapter.xml and this is the line logCat Error Pointed .
break;
CustomAdapter.Java
public class CustomAdapter extends BaseAdapter {
private Activity activity;
private ArrayList data;
private static LayoutInflater inflater=null;
public Resources res;
ListModel getList;
int size ;
int i=0;
public CustomAdapter(Activity a, ArrayList d,Resources resLocal, int size) {
activity = a;
data=d;
res = resLocal;
this.size = size;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
if(data.size()<=0)
return 1;
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView txt_Name;
public TextView txt_Status;
public TextView txt_Position;
public ImageButton imgbtn_senka;
public ImageButton imgbtn_fuenka;
//public TableRow tblrow_btn;
public RelativeLayout layoutbtn;
public ImageView image;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
final ViewHolder holder;
if(convertView==null){
/********** Inflate tabitem.xml file for each row ( Defined below ) ************/
vi = inflater.inflate(R.layout.customadapter, null);
holder=new ViewHolder();
holder.txt_Name = (TextView)vi.findViewById(R.id.txtmemberName);
holder.txt_Status = (TextView)vi.findViewById(R.id.txtmemberStatus);
holder.image = (ImageView)vi.findViewById(R.id.imgPlayer);
holder.imgbtn_fuenka = (ImageButton) vi.findViewById(R.id.btnfusenka);
holder.imgbtn_senka = (ImageButton) vi.findViewById(R.id.btnsenka);
holder.txt_Position = (TextView)vi.findViewById(R.id.txtposition);
holder.layoutbtn = (RelativeLayout)vi.findViewById(R.id.layoutbutton);
vi.setTag(holder);
}
else
holder=(ViewHolder)vi.getTag();
if(data.size()<=0)
{
holder.txt_Name.setText("No Data");
}
else
{
getList=null;
getList = (ListModel) data.get(position);
if(getList.getMemberStatus() == 3){
holder.txt_Status.setVisibility(View.INVISIBLE);
holder.imgbtn_fuenka.setVisibility(View.VISIBLE);
holder.imgbtn_senka.setVisibility(View.VISIBLE);
if(getList.getEntry() == 1){
holder.imgbtn_senka.setImageResource(R.drawable.sankagray);
holder.imgbtn_senka.setEnabled(false);
}
else if(getList.getEntry() == 0){
holder.imgbtn_fuenka.setImageResource(R.drawable.fusankagray);
holder.imgbtn_fuenka.setEnabled(false);
}
holder.imgbtn_senka.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String entry = "1";
CustomListViewAndroidExample sct = (CustomListViewAndroidExample)activity;
sct.updateData(position , entry);
holder.imgbtn_senka.setImageResource(R.drawable.sankagray);
holder.imgbtn_senka.setEnabled(false);
holder.imgbtn_fuenka.setEnabled(true);
holder.imgbtn_fuenka.setImageResource(R.drawable.fusanka);
}
});
holder.imgbtn_fuenka.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String entry = "0";
CustomListViewAndroidExample sct = (CustomListViewAndroidExample)activity;
sct.updateData(position , entry);
holder.imgbtn_fuenka.setImageResource(R.drawable.fusankagray);
holder.imgbtn_fuenka.setEnabled(false);
holder.imgbtn_senka.setEnabled(true);
holder.imgbtn_senka.setImageResource(R.drawable.sanka);
}
});
}
else{
holder.txt_Status.setVisibility(View.VISIBLE);
holder.imgbtn_fuenka.setVisibility(View.INVISIBLE);
holder.imgbtn_senka.setVisibility(View.INVISIBLE);
if(getList.getEntry() == 0){
holder.txt_Status.setText("未確認");
}
else if(getList.getEntry() == 1){
holder.txt_Status.setText("参加");
}
else if(getList.getEntry() == 2){
holder.txt_Status.setText("不参加");
}
else if(getList.getEntry() == 3){
holder.txt_Status.setText("取消");
}
}
holder.txt_Name.setText(getList.getMemberName());
holder.txt_Position.setText(getList.getPosition());
String url="http://10.0.2.2/football365/Photo/"+getList.getImage();
try {
Bitmap bitmap= BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
Bitmap resized = Bitmap.createScaledBitmap(bitmap, 76, 76, false);
holder.image.setImageBitmap(resized);
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// holder.image.setImageResource(res.getIdentifier("http://10.0.2.2/football365/Photo/"+getList.getImage(),null,null));
}
if(size == 1){
holder.txt_Name.setTextSize((float)20.0);
}
return vi;
}
public void changeSize(){
ViewHolder holder = new ViewHolder();
holder.txt_Position.setTextSize((float)18.0);
holder.txt_Name.setTextSize((float)20.0);
}
}
This is CustomAdapter.xml
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="#+id/tblrowtotal"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#drawable/blackrow2"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imglin1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:src="#drawable/liney" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_marginLeft="3dp"
android:id="#+id/imgPlayer"
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_gravity="left|top"
android:layout_marginTop="2dp"
android:scaleType="center"
style="#style/AppBaseTheme"
android:background="#null"
/>
</LinearLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingTop="0dip" >
<TableRow>
<TextView
android:id="#+id/txtmemberName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="15dp"
android:textColor="#FFFFFF"
android:textSize="13sp" />
</TableRow>
<ImageView
android:id="#+id/imgview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/linex" />
<TableRow android:layout_width="wrap_content" >
<ImageView
android:id="#+id/position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="10dp"
android:src="#drawable/c_position" />
<TextView
android:id="#+id/txtposition"
android:layout_width="45dp"
android:layout_height="30dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="7dp"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_marginLeft="0dp"
android:src="#drawable/liney" />
<RelativeLayout
android:id="#+id/layoutbutton"
android:layout_width="wrap_content"
android:gravity="right"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtmemberStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:gravity="center_horizontal"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<ImageButton
android:id="#+id/btnfusenka"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="3dp"
android:background="#null"
android:focusable="false"
android:src="#drawable/fusanka"/>
<ImageButton
android:id="#+id/btnsenka"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#null"
android:focusable="false"
android:src="#drawable/sanka"
/>
</RelativeLayout>
</TableRow>
<ImageView
android:id="#+id/img3"
android:layout_width="fill_parent"
android:layout_marginLeft="0dp"
android:layout_height="wrap_content"
android:src="#drawable/linex" />
</TableLayout>
</TableRow>
Try this:
txt_Position.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Float.parseFloat(18.0));
TRY THIS
txt_Position.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);