here console show ClassCastException but not show error line Number? Any one help me here?
if any one has idea about to find exact errorline number then suggest me plz?
here xml where i used ListView.
i have tried
1) removed Params which set by programatically
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adlayout"
android:background="#color/md_white_0">
<com.os.folder.and.file.locker.files.widget.BGridView
android:id="#+id/hide_view_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:numColumns="3"
android:stretchMode="columnWidth" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/hide_btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:background="#color/file_add"
android:onClick="onClick"
android:src="#drawable/ic_action_new" />
<LinearLayout
android:id="#+id/file_bottom_layout_tips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/unrecord" />
<TextView
android:id="#+id/file_bottom_txt_tips"
android:layout_width="match_parent"
android:layout_height="64dp"
android:gravity="center"
android:text=""
android:textColor="#color/md_black_2"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/pic_hide_btn_edit"
android:layout_width="match_parent"
android:layout_height="#dimen/title_height"
android:layout_above="#+id/adlayout"
android:layout_alignParentRight="true"
android:background="#color/md_black_1"
android:visibility="visible"
android:weightSum="4">
<LinearLayout
android:id="#+id/pic_hide_img_cancel"
android:layout_width="0dp"
android:layout_height="#dimen/title_height"
android:layout_weight="1"
android:gravity="center"
android:onClick="onClick">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/close" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="#dimen/title_height"
android:layout_weight="1"
android:gravity="center">
<CheckBox
android:id="#+id/item_file_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_selector" />
</LinearLayout>
<LinearLayout
android:id="#+id/pic_hide_img_recovery"
android:layout_width="0dp"
android:layout_height="#dimen/title_height"
android:layout_weight="1"
android:gravity="center"
android:onClick="onClick">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/unlock" />
</LinearLayout>
<LinearLayout
android:id="#+id/pic_hide_img_del"
android:layout_width="0dp"
android:layout_height="#dimen/title_height"
android:layout_weight="1"
android:gravity="center"
android:onClick="onClick">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/delete" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/adlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" />
</RelativeLayout>
here Java file, i have implemented from here listView
package com.os.folder.and.file.locker.files.activity;
import android.content.Intent;
import com.os.folder.and.file.locker.R;
import com.os.folder.and.file.locker.data.GroupImage;
import com.os.folder.and.file.locker.data.HideImage;
import com.os.folder.and.file.locker.files.adapter.BaseHideAdapter.OnListener;
import com.os.folder.and.file.locker.files.adapter.PicHideAdapter;
import com.os.folder.and.file.locker.files.entity.HideImageExt;
import com.os.folder.and.file.locker.files.widget.BGridView;
import com.os.folder.and.file.locker.service.GroupImageService;
import com.os.folder.and.file.locker.service.ImageService;
import java.util.List;
public class PicHideActivity extends BaseHideActivity implements OnListener {
protected static final String TAG = "PicHideActivity";
private int itemSize;
protected GroupImageService mGroupImageService;
protected ImageService mImageService;
protected void initUI() {
setContentView((int) R.layout.activity_file_hide_group);
setUI();
setTitleRID(R.string.pic_preview_title, R.string.pic_preview_title_edit);
setGridView();
this.mFile_bottom_txt_tips.setText(R.string.file_hide_txt_add_pic);
this.rid_string_type = R.string.pic_preview;
}
private void setGridView() {
this.itemSize = ((BGridView) findViewById(R.id.hide_view_list)).setGridView(getWindowManager(), 4, 4);
}
void initAdapter() {
BGridView adapterView = findViewById(R.id.hide_view_list);
this.mGroupImageService = new GroupImageService(this);
this.mImageService = new ImageService(this);
this.mBaseHideAdapter = new PicHideAdapter(this, this, this.itemSize);
adapterView.setAdapter(this.mBaseHideAdapter);
}
boolean delFolder() {
return false;
}
void addFolder() {}
public void addFile() {
Intent intent = new Intent(this, PicPreViewActivity.class);
intent.putExtra("beyondGroupId", this.mBaseHideAdapter.getGruopID());
startActivity(intent);
}
protected void recoveryFiles() {
for (Object imageModelView: this.mBaseHideAdapter.getHitFiles()) {
this.mImageService.unHideImage((HideImageExt) imageModelView);
}
}
protected void delFiles() {
for (Object hideImageExt: this.mBaseHideAdapter.getHitFiles()) {
this.mImageService.deleteAudioByPath((HideImageExt)
hideImageExt);
}
}
protected void openHolder(int groupID) {
List < GroupImage > groupList = this.mGroupImageService.getGroupFiles(groupID);
List < HideImage > list = this.mImageService.getHideImages(groupID);
this.mBaseHideAdapter.setHitFiles(groupList, list, groupID);
setHasData(groupList, list);
}
public void openHolder(Object object) {
GroupImage data = (GroupImage) object;
int groupID = -1;
if (data != null) {
groupID = data.getId().intValue();
}
openHolder(groupID);
}
}
and here is adapter code,
package com.os.folder.and.file.locker.files.adapter;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
//import android.widget.AbsListView.LayoutParams;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.DisplayImageOptions.Builder;
import com.nostra13.universalimageloader.core.ImageLoader;
import
com.nostra13.universalimageloader.core.download.ImageDownloader.Scheme;
import com.os.folder.and.file.locker.R;
import com.os.folder.and.file.locker.data.GroupImage;
import com.os.folder.and.file.locker.data.HideImage;
import com.os.folder.and.file.locker.files.activity.PhotoPreViewActivity;
import com.os.folder.and.file.locker.files.entity.GroupImageExt;
import com.os.folder.and.file.locker.files.entity.HideImageExt;
import java.util.ArrayList;
import java.util.List;
public class PicHideAdapter extends BaseHideAdapter {
private static final String TAG = "PicHideAdapter";
protected ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new Builder().showStubImage(R.drawable.default_picture).showImageForEmptyUri((int) R.drawable.default_picture).showImageOnFail((int) R.drawable.default_picture).cacheInMemory(true).cacheOnDisc(true).build();
private ViewGroup.LayoutParams params;
class PicHolder {
Object mData;
ImageView mImg_pre_preview;
View mItem_file_ok;
View mItem_file_pic;
PicHolder() {}
}
public PicHideAdapter(Context context, OnListener onListern, int itemSize) {
super(context, onListern);
this.params = new ViewGroup.LayoutParams(itemSize, itemSize);
}
public void clear() {
super.clear();
if (this.imageLoader != null) {
this.imageLoader.stop();
this.imageLoader = null;
}
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = this.mInflater.inflate(R.layout.item_file_hide_pic, null);
PicHolder picHolder = new PicHolder();
picHolder.mItem_file_pic = convertView.findViewById(R.id.item_file_pic);
picHolder.mItem_file_ok = convertView.findViewById(R.id.item_file_ok);
picHolder.mImg_pre_preview = (ImageView)
convertView.findViewById(R.id.img_pre_preview);
convertView.setTag(picHolder);
// convertView.setLayoutParams(this.params);
}
initView(convertView, position);
return convertView;
}
protected void initView(View view, final int position) {
int i = 8;
final PicHolder fileHolder = (PicHolder) view.getTag();
fileHolder.mImg_pre_preview.setImageBitmap(null);
Object data = getItem(position);
fileHolder.mData = data;
if (data instanceof HideImageExt) {
final HideImageExt hideImageView = (HideImageExt) data;
this.imageLoader.displayImage(Scheme.THUMBNAIL.wrap(hideImageView.getNewPathUrl()), fileHolder.mImg_pre_preview, this.options);
if (this.edit) {
View view2 = fileHolder.mItem_file_ok;
if (hideImageView.isEnable()) {
i = 0;
}
view2.setVisibility(i);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
boolean z;
int i = 0;
HideImageExt hideImageExt = hideImageView;
if (hideImageView.isEnable()) {
z = false;
} else {
z = true;
}
hideImageExt.setEnable(z);
View view = fileHolder.mItem_file_ok;
if (!hideImageView.isEnable()) {
i = 8;
}
view.setVisibility(i);
PicHideAdapter.this.updateSelect();
}
});
view.setOnLongClickListener(null);
return;
}
fileHolder.mItem_file_ok.setVisibility(8);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(PicHideAdapter.this.context, PhotoPreViewActivity.class);
intent.putParcelableArrayListExtra("list", (ArrayList)
PicHideAdapter.this.mList_HideFile);
intent.putExtra("id", position);
PicHideAdapter.this.context.startActivity(intent);
}
});
view.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
PicHideAdapter.this.doVibrator(PicHideAdapter.this.context);
PicHideAdapter.this.mOnListern.onLongClick(hideImageView);
return false;
}
});
} else if (data instanceof GroupImageExt) {
final GroupImageExt groupImageView = (GroupImageExt) data;
fileHolder.mItem_file_ok.setVisibility(8);
fileHolder.mImg_pre_preview.setImageResource(R.drawable.folder);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (PicHideAdapter.this.edit) {
PicHolder fileHolder = (PicHolder) v.getTag();
groupImageView.setEnable(!groupImageView.isEnable());
} else if (PicHideAdapter.this.mOnListern != null) {
PicHideAdapter.this.mOnListern.openHolder(groupImageView);
}
}
});
}
}
public void setHitFiles(List < ?>listGroup, List < ?>listFile, int groupID) {
this.mList_Group = GroupImageExt.transList((List < GroupImage > ) listGroup);
this.mList_HideFile = HideImageExt.transList((List < HideImage > ) listFile);
setGroup(groupID);
notifyDataSetChanged();
}
}
LayoutParams lp = new LayoutParams(-2, -2);
lp.setMargins(margin, margin, margin, margin);
setLayoutParams(lp);
resolved..by removing this param
Related
i have a textView in SliderView like this
activitity_slider.xml
<androidx.viewpager.widget.ViewPager
android:id="#+id/slideViewPager"
android:layout_width="match_parent"
slide_layout.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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
android:background="#color/white">
<LinearLayout
android:id="#+id/HareketEkranı"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:orientation="vertical"
>
<androidx.cardview.widget.CardView
android:id="#+id/hareket"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
<ImageView
android:id="#+id/HareketResmi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:contentDescription="Hareket"/>
//android:src="#drawable/ic_armcircle"
<com.jjoe64.graphview.GraphView
android:id="#+id/haraketdatasi"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Hareket"
android:layout_weight="1"
android:textColor="#color/darkTextColor"
android:textSize="24sp" />
<TextView
android:id="#+id/HareketAdi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textAlignment="gravity"
android:gravity="right"
android:text="Armcircle"
android:textColor="#color/red"
android:layout_weight="1"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/TekrarYazisiSlide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Tekrar"
android:layout_weight="1"
android:textColor="#color/darkTextColor"
android:textSize="24sp" />
<TextView
android:id="#+id/TekrarSayisiSlide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="TekrarSayisi"
android:textAlignment="gravity"
android:gravity="right"
android:layout_weight="1"
android:textColor="#color/red"
android:textSize="24sp" />
<TextView
android:id="#+id/kesme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="/"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="24sp" />
<TextView
android:id="#+id/TekrarhedefiSlide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="25"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="24sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</RelativeLayout>
UPDATE !
SliderAdapter.java
package gymholix.assistx;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
public class SliderAdapter extends PagerAdapter {
Context context;
LayoutInflater layoutInflater;
public SliderAdapter(Context context){
this.context = context;
}
//Arrays
public int[] slide_images = {
R.drawable.ic_armcircle,
R.drawable.ic_ropejump,
R.drawable.ic_jumpingjack,
R.drawable.ic_burpee,
R.drawable.ic_squat
};
public String[] slide_headings = {
"ArmCircle",
"RopeJump",
"JumpingJack",
"Burpee",
"Squat"
};
/*public String[] tekrar_sayisi = {
"0",
"0",
"0",
"0",
"0"*/
public int[] tekrar_sayisi = {
1,
2,
3,
4,
5
};
#Override
public int getCount() {
return slide_headings.length;
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object object) {
return view == (RelativeLayout) object;
}
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, int position) {
layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view =layoutInflater.inflate(R.layout.slide_layout, container, false);
ImageView slideImageView = (ImageView) view.findViewById(R.id.HareketResmi);
TextView slideHeading = (TextView) view.findViewById(R.id.HareketAdi);
TextView slideTekraSayisi = (TextView) view.findViewById(R.id.TekrarSayisiSlide);
slideImageView.setImageResource((slide_images[position]));
slideHeading.setText(slide_headings[position]);
slideTekraSayisi.setText(String.valueOf(tekrar_sayisi[position]));
container.addView(view);
return view;
}
#Override
public void destroyItem(#NonNull ViewGroup container, int position, #NonNull Object object) {
}
}
Slider.Java
package gymholix.assistx;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Slider extends AppCompatActivity {
private LinearLayout mDotLayout;
private String asd;
private int asdf;
TextView DenemeSayiCek;
int position;
View view;
int count;
View viewFix;
Context context;
//Sensors---------------------------------------------------------------------------------------
private Accelerometer accelerometer;
private Gyroscope gyroscope;
public double[] acc={3.00,2.00,1.00};
public double[] gyr={3.00,2.00,1.00};
//Sensors---------------------------------------------------------------------------------------
//Main------------------------------------------------------------------------------------------
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Antreman antreman = new Antreman();
context = this;
setContentView(R.layout.activity_slider);
ViewPager AktifHareket = findViewById(R.id.slideViewPager);
mDotLayout = findViewById(R.id.dotsLayout);
SliderAdapter sliderAdapter = new SliderAdapter(this);
AktifHareket.setAdapter((sliderAdapter));
addDotsIndicator();
//Saydir Buton------------------------------------------------------------------------------
TextView Deneme = findViewById(R.id.deneme);
TextView Deneme4 = findViewById(R.id.deneme4);
TextView Deneme3 = findViewById(R.id.deneme3);
TextView Deneme2 = findViewById(R.id.deneme2);
Button Saydir = findViewById(R.id.SaydirSlide);
Button Saydir2 = findViewById(R.id.Saydir2Slide);
Saydir.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
position = AktifHareket.getCurrentItem();
view = AktifHareket.getChildAt(position);
count = AktifHareket.indexOfChild(view);
viewFix = AktifHareket.getChildAt(count);
DenemeSayiCek = viewFix.findViewById(R.id.TekrarSayisiSlide);
asd = DenemeSayiCek.getText().toString();
asdf = Integer.parseInt(asd);
asdf++;
DenemeSayiCek.setText(String.valueOf(asdf));
Deneme.setText(String.valueOf(asd));
Deneme2.setText(String.valueOf(position));
Deneme3.setText(String.valueOf(asdf));
Deneme4.setText(String.valueOf(SliderAdapter.POSITION_NONE));
}
});
//Saydir Buton------------------------------------------------------------------------------
//ImageButton-------------------------------------------------------------------------------
ImageView logoImage = findViewById(R.id.logo);
logoImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
antreman.AntremanSayfasi(context);
}
});
antreman.AntremanSayfasi(context);//Açılışta Sayfayı açsın diye
//ImageButton-------------------------------------------------------------------------------
//Sensors-----------------------------------------------------------------------------------
accelerometer = new Accelerometer(this);
gyroscope = new Gyroscope(this);
accelerometer.setListner(new Accelerometer.Listner() {
#Override
public void onTranslation(float ax, float ay, float az) {
setAccValue(ax, ay, az);
Antreman.GetSensorValues.OnAccelerometerChangeValues = acc;
}
});
gyroscope.setListner(new Gyroscope.Listner() {
#Override
public void onRotation(float gx, float gy, float gz) {
setGyroValue(gx, gy, gz);
Antreman.GetSensorValues.OnGyroscopeChangeValues = gyr;
//OnSensorChangeValues.add(1, String.valueOf(gyr) );
}
});
/* Saydir2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});*/
//Sensors-----------------------------------------------------------------------------------
}
//Sensors---------------------------------------------------------------------------------------
protected void onResume(){
super.onResume();
accelerometer.register();
gyroscope.register();
}
protected void onPouse(){
super.onPause();
accelerometer.unregister();
gyroscope.unregister();
}
//Sensors---------------------------------------------------------------------------------------
//SensorsValueGetAndSet-------------------------------------------------------------------------
public double[] setAccValue(float ac, float bc, float cc){
this.acc[0] = ac;
this.acc[1] = bc;
this.acc[2] = cc;
return acc;
}
public double[] setGyroValue(float qq, float wq, float eq){
this.gyr[0] = qq;
this.gyr[1] = wq;
this.gyr[2] = eq;
return gyr;
}
public void getAccValue(float ac, float bc, float cc){
ac = (float) acc[0];
bc = (float) acc[1];
cc = (float) acc[2];
}
public void getGyroValue(float qq, float wq, float eq){
qq = (float) gyr[0];
wq = (float) gyr[1];
eq = (float) gyr[2];
}
//SensorsValueGetAndSet-------------------------------------------------------------------------
public void addDotsIndicator(){
TextView[] mDots = new TextView[3];
for(int i = 0; i < mDots.length; i++){
mDots[i] = new TextView(this);
mDots[i].setText(Html.fromHtml("•"));
mDots[i].setTextSize(35);
mDots[i].setTextColor(getResources().getColor(R.color.colorPrimaryDark));
mDotLayout.addView(mDots[i]);
}
}
//----------------------------------------------------------------------------------------------
}
the weird thing about this code is; while running the button changes the text value correctly in the first pager, and the seckond one but when it comes the third one while it changes the value it resets the first pagers shown value but the getText() method inherits the correct value but the text is frozen and it cant be changed any more, after that the other page's values cant be changed either, but the getText() method still works fine and gets the correct value.
any idea will speed up my debuging process thanx anyway...
adding this snipped solved the problem, it is a must to define borders to the pager
#Override
protected void onCreate(Bundle savedInstanceState) {
...
int size = sliderAdapter.slide_headings.length;
AktifHareket.setOffscreenPageLimit(size);
I made a custom view for my ListView My Custom View extends LinearLayout, It acts as an expandable Item for a normal ListView So the bug I am getting now is really weird, So I have my ListView attributes set to
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
So the height is at wrap_content lets take a note of that, as that will help us understand the issue.
So this is the video of how my ListVIew looks. The first Expandable Item is visible but the others don't fill the screen, I am pretty confident this is because of wrap_content but as soon as I expand one of the item it fill the whole screen. How can I resolve this? My guess is It's because the ListView isn't updating the other items? this is my CustomView code
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import java.util.ArrayList;
import java.util.List;
public class ExpandableInnerListView extends LinearLayout {
private ListAdapter adapter;
private DataChangeObserver dataChangeObserver;
private View mainView;
private List<View> reusableViews = new ArrayList<>();
private boolean viewsHidden = true;
int mDividerHeight = 1;
public ExpandableInnerListView(Context context) {
this(context, null);
}
public ExpandableInnerListView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ExpandableInnerListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOrientation(VERTICAL);
}
public void setAdapter(ListAdapter adapter) {
if (this.adapter != null && dataChangeObserver != null) {
this.adapter.unregisterDataSetObserver(dataChangeObserver);
}
this.adapter = adapter;
}
public void setMainView(View mainView) {
this.mainView = mainView;
}
public void toggle() {
viewsHidden = !viewsHidden;
dataChangeObserver.onInvalidated();
}
#Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (adapter != null) {
dataChangeObserver = new DataChangeObserver();
adapter.registerDataSetObserver(dataChangeObserver);
setupView();
}
}
#Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (adapter != null && dataChangeObserver != null) {
adapter.unregisterDataSetObserver(dataChangeObserver);
dataChangeObserver = null;
}
}
private void setupView() {
this.removeAllViews();
setupMainLayout();
setupInnerView();
}
public void setupMainLayout() {
if (mainView == null) {
throw new NullPointerException("Main View cannot be null!");
}
addView(mainView);
}
public void setupInnerView() {
if (viewsHidden) return;
int reusableCount = reusableViews.size();
int count = adapter.getCount();
for (int i = 0; i < count; i++) {
View converView = null;
if (i < reusableCount) {
converView = reusableViews.get(i);
}
View view = adapter.getView(i, converView, this);
if (i >= reusableCount) {
reusableViews.add(view);
}
if(mDividerHeight > 0) {
View divider = new View(getContext());
divider.setBackground(new ColorDrawable(0xFFCCCCCC));
LinearLayout.LayoutParams dividerLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mDividerHeight);
divider.setLayoutParams(dividerLayoutParams);
addView(divider);
}
addView(view);
}
}
private class DataChangeObserver extends DataSetObserver {
#Override
public void onChanged() {
super.onChanged();
setupView();
}
#Override
public void onInvalidated() {
super.onInvalidated();
setupView();
}
}
}
and this is my whole Fragment View 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">
<include
android:id="#+id/back_button_container"
layout="#layout/kik_back_button" />
<FrameLayout
android:id="#+id/topbar"
android:layout_width="match_parent"
android:layout_height="#dimen/native_topbar_height"
android:layout_alignParentTop="true"
android:layout_toEndOf="#id/back_button_container"
android:layout_toRightOf="#id/back_button_container" />
<include
android:id="#+id/nav_bar_shadow"
layout="#layout/navbar_underline"
android:layout_width="fill_parent"
android:layout_height="#dimen/navbar_underline_height"
android:layout_below="#id/topbar" />
<EditText
android:id="#android:id/edit"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_below="#+id/topbar"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:layout_marginEnd="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:drawablePadding="15dp"
android:hint="Search Settings"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:paddingEnd="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingStart="16dp"
android:textStyle="normal"
android:typeface="sans" />
<ImageView
android:id="#android:id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignEnd="#android:id/edit"
android:layout_alignRight="#android:id/edit"
android:layout_alignTop="#android:id/edit"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="12dp"
android:src="#drawable/delete_gray"
android:visibility="gone" />
<View
android:id="#+id/top_divider"
android:layout_width="match_parent"
android:layout_height="1.0px"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#android:id/edit"
android:layout_marginTop="15dp"
android:background="#color/list_divider_color" />
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/top_divider"
android:divider="#null"
android:dividerHeight="0dp" />
<View
android:id="#+id/bottom_divider"
android:layout_width="match_parent"
android:layout_below="#android:id/list"
android:layout_height="1.0px"
android:background="#color/list_divider_color" />
<TextView
android:id="#android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No Settings Found"
android:textSize="19.0sp"
android:visibility="gone" />
</RelativeLayout>
Would be really generous if someone can spot where the error happens and how to resolve it, and along side if any other error can happen at certain cases.
Look's like the issue was very minor. I ha to reset the view when I set the mainView
public void setMainView(View mainView) {
this.mainView = mainView;
setupView();
}
Try adapter.notifyDataSetChanged() when new list is updated.
I'm implementing adapter for recycleview in android, but it throws error Resource ID #0x7f0d00aa type #0x12 is not valid.
This is my card layout for client_info_fragment_revision_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="2dp"
android:layout_margin="7dp"
android:clickable="true"
android:focusable="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/revMainLayout">
<!--TOP-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/revRelativeTop">
<ImageView android:id="#+id/imagePartRevision"
android:layout_width="28dp"
android:layout_height="28dp"
android:scaleType="fitXY"
android:layout_marginLeft="7dp" android:layout_marginTop="5dp"
android:src="#drawable/ic_indicator_program"/>
<TextView
android:id="#+id/partRevision"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:maxLines="2"
android:padding="10dp"
android:text="Paper"
android:textSize="16sp" android:layout_marginLeft="34dp"/>
<TextView
android:id="#+id/deadlineRevision"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="23-04-2016"
android:textSize="16sp"
android:padding="10dp"
android:layout_marginRight="7dp"/>
</RelativeLayout>
<!--MIDDLE-->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/revLinearMiddle">
<View
android:id="#+id/divider1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#a4b9adba"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:id="#+id/listViewRevision"/>
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#a4b9adba"/>
</LinearLayout>
<!--BOTTOM-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/revRelativeBottom">
<TextView
android:id="#+id/statusRevision"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/statusRevisionIndicator"
android:maxLines="2"
android:padding="10dp"
android:text="On Progress"
android:textSize="16sp"/>
<ImageView
android:id="#+id/statusRevisionIndicator"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_alignBottom="#+id/statusRevision"
android:layout_alignParentRight="true"
android:layout_below="#id/divider"
android:layout_marginRight="7dp" android:layout_centerVertical="true"
android:layout_marginBottom="5dp" android:src="#drawable/ic_indicator_not_finished"/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
And this is code for my adapter RevisionRecycleCardsAdapter.java:
package com.putraxor.prola.skripsi.client.activity.profileui;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.putraxor.prola.skripsi.R;
import com.putraxor.prola.skripsi.pojo.Revisi;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by Putra on 27/03/2016.
*/
public class RevisionRecycleCardsAdapter extends RecyclerView.Adapter<RevisionRecycleCardsAdapter.CardViewHolder> {
private ArrayList<Revisi> revision_list;
Context context;
public static class CardViewHolder extends RecyclerView.ViewHolder{
ImageView imagePartRevision;
ImageView statusRevisionIndicator;
TextView partRevision;
TextView deadlineRevision;
TextView statusRevision;
ListView listViewRevision;
public CardViewHolder(View itemView) {
super(itemView);
imagePartRevision = (ImageView)itemView.findViewById(R.id.imagePartRevision);
statusRevisionIndicator = (ImageView)itemView.findViewById(R.id.statusRevisionIndicator);
partRevision = (TextView)itemView.findViewById(R.id.partRevision);
deadlineRevision = (TextView)itemView.findViewById(R.id.deadlineRevision);
statusRevision = (TextView)itemView.findViewById(R.id.statusRevision);
listViewRevision = (ListView)itemView.findViewById(R.id.listViewRevision);
}
}
public RevisionRecycleCardsAdapter(ArrayList<Revisi> revision) {
this.revision_list = revision;
}
#Override
public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
this.context = parent.getContext();
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.client_info_fragment_revision_layout, parent, false);
CardViewHolder cardViewHolder = new CardViewHolder(view);
return cardViewHolder;
}
#Override
public void onBindViewHolder(final CardViewHolder holder, final int listPosition) {
Revisi rev = revision_list.get(listPosition);
int srcImagePartRevision = rev.getBagian().equalsIgnoreCase("Paper") ? R.drawable.ic_indicator_paper : R.drawable.ic_indicator_program;
int srcStateIndicator = rev.isSelesai() ? R.drawable.ic_indicator_finished : R.drawable.ic_indicator_not_finished;
String status = rev.isSelesai()?"Revisions Finished" : "On Process";
holder.imagePartRevision.setImageResource(srcImagePartRevision);
holder.partRevision.setText(rev.getBagian());
holder.deadlineRevision.setText(rev.getDeadline());
holder.statusRevision.setText(status);
holder.statusRevisionIndicator.setImageResource(srcStateIndicator);
String[] values = rev.getRevisi();
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < values.length; ++i) {
list.add(values[i]);
}
StableArrayAdapter adapter = new StableArrayAdapter(this.context, R.id.listViewRevision, list);
holder.listViewRevision.setAdapter(adapter);
}
#Override
public int getItemCount() {
return revision_list.size();
}
private class StableArrayAdapter extends ArrayAdapter<String> {
HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
public StableArrayAdapter(Context context, int textViewResourceId, List<String> objects) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
#Override
public long getItemId(int position) {
String item = getItem(position);
return mIdMap.get(item);
}
#Override
public boolean hasStableIds() {
return true;
}
}
}
Change your code in
#Override
public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.R.layout.client_info_fragment_revision_layout, parent, false);
CardViewHolder holder = new CardViewHolder (view);
}
It's just for debug purpose:
If you are using Android studio then open your R.java under folder
build->generated->source->r->debug->yourpackagename->R.java
Then search 0x7f0d00aa in the file; It will be like
public static final int TextView01=0x7f0d00aa;
Search the corresponding ID in xml files under resources folder. Then check the XML content syntax,naming,source etc.
I developed a music player app from a tutorial i watched
and when i ran it on a device that didn't contain an sdcard
it crashed.So i cant publish it so what can i add or change
that will enable it to read music from internal storage.
Java class
package com.example.playaudioexample;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.math.BigDecimal;
public class PlayAudioExample extends ListActivity {
private static final int UPDATE_FREQUENCY = 500;
private static final int STEP_VALUE = 4000;
private MediaCursorAdapter mediaAdapter = null;
private TextView selelctedFile = null;
private SeekBar seekbar = null;
private MediaPlayer player = null;
private ImageButton playButton = null;
private ImageButton prevButton = null;
private ImageButton nextButton = null;
private ImageButton floatButton = null;
private ImageButton floatButton2 = null;
private boolean isStarted = true;
private String currentFile = "";
private boolean isMoveingSeekBar = false;
private final Handler handler = new Handler();
private final Runnable updatePositionRunnable = new Runnable() {
public void run() {
updatePosition();
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_play_audio_example);
selelctedFile = (TextView) findViewById(R.id.selectedfile);
seekbar = (SeekBar) findViewById(R.id.seekbar);
playButton = (ImageButton) findViewById(R.id.play);
prevButton = (ImageButton) findViewById(R.id.prev);
nextButton = (ImageButton) findViewById(R.id.next);
floatButton = (ImageButton) findViewById(R.id.imageinfo);
floatButton2 = (ImageButton)findViewById(R.id.imageMessage);
floatButton2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"CONTACT:gabriel.agbese2001#gmail.com",Toast.LENGTH_LONG).show();
}
});
floatButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"Developed by:Gabriel Agbese",Toast.LENGTH_LONG).show();
}
});
player = new MediaPlayer();
player.setOnCompletionListener(onCompletion);
player.setOnErrorListener(onError);
seekbar.setOnSeekBarChangeListener(seekBarChanged);
Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
if (null != cursor) {
cursor.moveToFirst();
mediaAdapter = new MediaCursorAdapter(this, R.layout.listitem, cursor);
setListAdapter(mediaAdapter);
playButton.setOnClickListener(onButtonClick);
nextButton.setOnClickListener(onButtonClick);
prevButton.setOnClickListener(onButtonClick);
}
}
#Override
protected void onListItemClick(ListView list, View view, int position, long id) {
super.onListItemClick(list, view, position, id);
currentFile = (String) view.getTag();
startPlay(currentFile);
}
#Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacks(updatePositionRunnable);
player.stop();
player.reset();
player.release();
player = null;
}
private void startPlay(String file) {
Log.i("Selected: ", file);
selelctedFile.setText(file);
seekbar.setProgress(0);
player.stop();
player.reset();
try {
player.setDataSource(file);
player.prepare();
player.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
seekbar.setMax(player.getDuration());
playButton.setImageResource(android.R.drawable.ic_media_pause);
updatePosition();
isStarted = true;
}
private void stopPlay() {
player.stop();
player.reset();
playButton.setImageResource(android.R.drawable.ic_media_play);
handler.removeCallbacks(updatePositionRunnable);
seekbar.setProgress(0);
isStarted = false;
}
private void updatePosition() {
handler.removeCallbacks(updatePositionRunnable);
seekbar.setProgress(player.getCurrentPosition());
handler.postDelayed(updatePositionRunnable, UPDATE_FREQUENCY);
}
private class MediaCursorAdapter extends SimpleCursorAdapter {
public MediaCursorAdapter(Context context, int layout, Cursor c) {
super(context, layout, c,
new String[]{MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.TITLE, MediaStore.Audio.AudioColumns.DURATION},
new int[]{R.id.displayname, R.id.title, R.id.duration});
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
TextView title = (TextView) view.findViewById(R.id.title);
TextView name = (TextView) view.findViewById(R.id.displayname);
TextView duration = (TextView) view.findViewById(R.id.duration);
name.setText(cursor.getString(
cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)));
title.setText(cursor.getString(
cursor.getColumnIndex(MediaStore.MediaColumns.TITLE)));
long durationInMs = Long.parseLong(cursor.getString(
cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DURATION)));
double durationInMin = ((double) durationInMs / 1000.0) / 60.0;
durationInMin = new BigDecimal(Double.toString(durationInMin)).setScale(2, BigDecimal.ROUND_UP).doubleValue();
duration.setText("" + durationInMin);
view.setTag(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)));
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.listitem, parent, false);
bindView(v, context, cursor);
return v;
}
}
private View.OnClickListener onButtonClick = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.play: {
if (player.isPlaying()) {
handler.removeCallbacks(updatePositionRunnable);
player.pause();
playButton.setImageResource(android.R.drawable.ic_media_play);
} else {
if (isStarted) {
player.start();
playButton.setImageResource(android.R.drawable.ic_media_pause);
updatePosition();
} else {
startPlay(currentFile);
}
}
break;
}
case R.id.next: {
int seekto = player.getCurrentPosition() + STEP_VALUE;
if (seekto > player.getDuration())
seekto = player.getDuration();
player.pause();
player.seekTo(seekto);
player.start();
break;
}
case R.id.prev: {
int seekto = player.getCurrentPosition() - STEP_VALUE;
if (seekto < 0)
seekto = 0;
player.pause();
player.seekTo(seekto);
player.start();
break;
}
}
}
};
private MediaPlayer.OnCompletionListener onCompletion = new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
stopPlay();
}
};
private MediaPlayer.OnErrorListener onError = new MediaPlayer.OnErrorListener() {
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
};
private SeekBar.OnSeekBarChangeListener seekBarChanged = new SeekBar.OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
isMoveingSeekBar = false;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
isMoveingSeekBar = true;
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (isMoveingSeekBar) {
player.seekTo(progress);
Log.i("OnSeekBarChangeListener", "onProgressChanged");
}
}
};
}
content_play_audio_example.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0a0b0e"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".PlayAudioExample">
<ListView
android:id="#android:id/list"
android:background="#f0fffdfd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:layout_weight="1.0" />
<LinearLayout
android:layout_width="wrap_content"
android:background="#f7262624"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="#drawable/oval"
android:id="#+id/imageinfo"
android:src="#android:drawable/ic_dialog_info"
android:layout_gravity="center_horizontal" />
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="#drawable/oval2"
android:id="#+id/imageMessage"
android:src="#android:drawable/ic_dialog_email" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="#f7262624"
android:background="#android:drawable/screen_background_light"
android:orientation="vertical"
android:padding="10dip">
<TextView
android:id="#+id/selectedfile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="center_horizontal"
android:singleLine="true"
android:text="No file selected"
android:textColor="#android:color/black" />
<SeekBar
android:id="#+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
android:paddingBottom="10dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/screen_background_light"
android:gravity="center"
android:backgroundTint="#ca030b03"
android:orientation="horizontal">
<ImageButton
android:id="#+id/prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000"
android:src="#android:drawable/ic_media_previous" />
<ImageButton
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000"
android:src="#android:drawable/ic_media_next" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
listitem.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0a0b0e"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".PlayAudioExample">
<ListView
android:id="#android:id/list"
android:background="#f0fffdfd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:layout_weight="1.0" />
<LinearLayout
android:layout_width="wrap_content"
android:background="#f7262624"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="#drawable/oval"
android:id="#+id/imageinfo"
android:src="#android:drawable/ic_dialog_info"
android:layout_gravity="center_horizontal" />
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="#drawable/oval2"
android:id="#+id/imageMessage"
android:src="#android:drawable/ic_dialog_email" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="#f7262624"
android:background="#android:drawable/screen_background_light"
android:orientation="vertical"
android:padding="10dip">
<TextView
android:id="#+id/selectedfile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="center_horizontal"
android:singleLine="true"
android:text="No file selected"
android:textColor="#android:color/black" />
<SeekBar
android:id="#+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
android:paddingBottom="10dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/screen_background_light"
android:gravity="center"
android:backgroundTint="#ca030b03"
android:orientation="horizontal">
<ImageButton
android:id="#+id/prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000"
android:src="#android:drawable/ic_media_previous" />
<ImageButton
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000"
android:src="#android:drawable/ic_media_next" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have made a simple demo android app,In that I am getting some Images url from the API,And I am filling an arrayList with them.I want to made a slideshow of that imageurl from the server ,I have seen the view flipper example but not getting how to do it in my case.
ViewFlipperAdapter.java
package com.epe.smaniquines.adapter;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.epe.smaniquines.R;
import com.epe.smaniquines.adapter.CatalogAdapter.Viewholder;
import com.epe.smaniquines.util.Const;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
public class FlipperAdapter extends BaseAdapter {
ArrayList<String> urls;
private Context mContext;
private DisplayImageOptions options;
public static ImageLoader imageLoader;
public FlipperAdapter(Context paramContext, ArrayList<String> urls) {
this.urls = urls;
this.mContext = paramContext;
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(paramContext));
options = new DisplayImageOptions.Builder().cacheOnDisc(true)
.showStubImage(R.drawable.noimage)
.showImageOnFail(R.drawable.noimage).build();
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return urls.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return urls.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
LayoutInflater localLayoutInflater = (LayoutInflater) this.mContext
.getSystemService("layout_inflater");
Viewholder localViewholder = null;
if (paramView == null) {
paramView = localLayoutInflater.inflate(R.layout.raw_flip,
paramViewGroup, false);
localViewholder = new Viewholder();
localViewholder.proImg = ((ImageView) paramView
.findViewById(R.id.iv_flip));
paramView.setTag(localViewholder);
} else {
localViewholder = new Viewholder();
localViewholder = (Viewholder) paramView.getTag();
}
imageLoader.displayImage(urls.get(paramInt), localViewholder.proImg,
options);
return paramView;
}
static class Viewholder {
ImageView proImg;
}
}
raw.flip
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp" >
<ImageView
android:id="#+id/iv_flip"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
main.java
package com.epe.smaniquines.ui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Timer;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterViewFlipper;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
import com.epe.smaniquines.R;
import com.epe.smaniquines.adapter.FlipperAdapter;
import com.epe.smaniquines.util.Const;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
public class DetailsActivity extends Activity implements OnClickListener {
ImageView proImage, ivSave, ivInfo, ivPlay, ivBak, iv_share;
RelativeLayout rl_botm, rl_option;
TextView tv_facebuk, tv_twiter, tv_nothanks, tv_email, tv_save;
String big_img;
ArrayList<String> resultArray;
private DisplayImageOptions options;
public static ImageLoader imageLoader;
RelativeLayout rl_info;
public boolean flag = false;
int i = 0;
private int PicPosition;
private Handler handler = new Handler();
int mFlipping = 0;
ViewFlipper viewFlipper;
Timer timer;
int flagD = 0;
String data;
String shareType;
File image;
#Override
protected 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.activity_detail);
initialize();
/*
* Intent i = getIntent(); data = i.getStringExtra("data"); shareType =
* i.getStringExtra("type");
*/
big_img = getIntent().getStringExtra(Const.TAG_BIG_IMG);
resultArray = getIntent().getStringArrayListExtra("array");
System.out.println("::::::::::::::ArraySize::::::::" + resultArray);
imageLoader.displayImage(big_img, proImage, options);
ivInfo.setOnClickListener(this);
ivPlay.setOnClickListener(this);
tv_email.setOnClickListener(this);
tv_facebuk.setOnClickListener(this);
tv_nothanks.setOnClickListener(this);
tv_save.setOnClickListener(this);
tv_twiter.setOnClickListener(this);
iv_share.setOnClickListener(this);
ivBak.setOnClickListener(this);
// viewFlipper = (ViewFlipper) findViewById(R.id.flipper);
imageLoader.displayImage(big_img, proImage, options);
proImage.postDelayed(swapImage, 3000);
}
public void open(View view) {
/*
* Intent sharingIntent = new Intent(Intent.ACTION_SEND); screenshotUri
* = Uri.parse(big_img); sharingIntent.setType("image/*");
*/
/*
* sharingIntent .putExtra(Intent.EXTRA_TEXT,
* "Body text of the new status");
* sharingIntent.putExtra(Intent.EXTRA_TITLE, "Traffic At");
* sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
* startActivity(Intent.createChooser(sharingIntent,
* "Share image using"));
*/
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello test"); // <- String
Uri screenshotUri = Uri.parse(image.getPath());
shareIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(shareIntent, "Share image using"));
}
void initialize() {
proImage = (ImageView) findViewById(R.id.iv_det);
ivInfo = (ImageView) findViewById(R.id.iv_info);
ivPlay = (ImageView) findViewById(R.id.iv_play);
ivBak = (ImageView) findViewById(R.id.iv_back);
rl_botm = (RelativeLayout) findViewById(R.id.rl_bottom);
rl_option = (RelativeLayout) findViewById(R.id.rl_options);
tv_save = (TextView) findViewById(R.id.tv_save);
tv_email = (TextView) findViewById(R.id.tv_email);
tv_facebuk = (TextView) findViewById(R.id.tv_facebook);
tv_nothanks = (TextView) findViewById(R.id.tv_no_thanks);
tv_twiter = (TextView) findViewById(R.id.tv_twiter);
rl_option.setVisibility(View.GONE);
iv_share = (ImageView) findViewById(R.id.iv_share);
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration
.createDefault(DetailsActivity.this));
rl_info = (RelativeLayout) findViewById(R.id.rl_info);
rl_info.setVisibility(View.GONE);
resultArray = new ArrayList<String>();
}
#SuppressLint("NewApi")
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_share:
rl_option.setVisibility(View.VISIBLE);
break;
case R.id.iv_play:
proImage.setVisibility(View.GONE);
AdapterViewFlipper flipper = (AdapterViewFlipper) findViewById(R.id.flipper);
flipper.setAdapter(new FlipperAdapter(DetailsActivity.this,
resultArray));
break;
case R.id.iv_back:
finish();
break;
case R.id.tv_email:
rl_option.setVisibility(View.GONE);
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL,
new String[] { "youremail#yahoo.com" });
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email,
"Choose an Email client :"));
break;
case R.id.tv_save:
save();
rl_option.setVisibility(View.GONE);
break;
case R.id.tv_facebook:
save();
open(v);
rl_option.setVisibility(View.GONE);
break;
case R.id.tv_no_thanks:
rl_option.setVisibility(View.GONE);
break;
case R.id.tv_twiter:
rl_option.setVisibility(View.GONE);
break;
case R.id.iv_info:
rl_option.setVisibility(View.GONE);
if (flag) {
rl_info.setVisibility(View.VISIBLE);
flag = false;
} else {
rl_info.setVisibility(View.GONE);
flag = true;
}
break;
}
}
// slide show..!!!
MediaPlayer introSound, bellSound;
Runnable swapImage = new Runnable() {
#Override
public void run() {
myslideshow();
handler.postDelayed(this, 1000);
}
};
private void myslideshow() {
PicPosition = resultArray.indexOf(big_img);
if (PicPosition >= resultArray.size())
PicPosition = resultArray.indexOf(big_img); // stop
else
resultArray.get(PicPosition);// move to the next gallery element.
}
//
// SAVE TO SD CARD..!!
void save() {
BitmapDrawable drawable = (BitmapDrawable) proImage.getDrawable();
Bitmap bitmap = drawable.getBitmap();
File sdCardDirectory = Environment.getExternalStorageDirectory();
File dir = new File(sdCardDirectory.getAbsolutePath()
+ "/3sManiquines/");
image = new File(sdCardDirectory, "3s_" + System.currentTimeMillis()
+ ".png");
dir.mkdirs();
boolean success = false;
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (success) {
addImageToGallery(dir + "", DetailsActivity.this);
Toast.makeText(getApplicationContext(), "Image saved with success",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error during image saving", Toast.LENGTH_LONG).show();
}
}//
public static void addImageToGallery(final String filePath,
final Context context) {
ContentValues values = new ContentValues();
values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(Images.Media.MIME_TYPE, "image/png");
values.put(MediaStore.MediaColumns.DATA, filePath);
context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI,
values);
}
// facebook...
public void sharetext(String text) // Text to be shared
{
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(android.content.Intent.EXTRA_SUBJECT, "TITLE");
share.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(share, "Share via"));
finish();
}
public void shareimage(String text) // argument is image file name with
// extention
{
Intent shareimage = new Intent(android.content.Intent.ACTION_SEND);
shareimage.setType("*/*");// for all
shareimage.setClassName("com.android.mms",
"com.android.mms.ui.ComposeMessageActivity");
shareimage.putExtra(Intent.EXTRA_STREAM, resultArray.indexOf(big_img));
startActivity(Intent.createChooser(shareimage, "Share Image"));
finish();
}
}
main.xaml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/rl_det_hdr"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#drawable/bottom_nav_bg" >
<ImageView
android:id="#+id/iv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:background="#drawable/btn_back" />
<TextView
android:id="#+id/titledetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="10dp"
android:text="CATALOG"
android:textColor="#ffffff"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_main_det"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_bottom"
android:layout_below="#+id/rl_det_hdr"
android:padding="10dp" >
<ImageView
android:id="#+id/iv_det"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" />
<AdapterViewFlipper
android:id="#+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_bottom"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/frame"
android:visibility="gone" >
<TextView
android:id="#+id/tv_twiter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Twitter"
android:textColor="#1D88FC"
android:textSize="20dp" />
<View
android:id="#+id/sep1"
android:layout_width="fill_parent"
android:layout_height="0.75dp"
android:layout_below="#+id/tv_twiter"
android:background="#cecece" />
<TextView
android:id="#+id/tv_facebook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sep1"
android:gravity="center"
android:padding="10dp"
android:text="Facebook"
android:textColor="#1D88FC"
android:textSize="20dp" />
<View
android:id="#+id/sep2"
android:layout_width="fill_parent"
android:layout_height="0.75dp"
android:layout_below="#+id/tv_facebook"
android:background="#cecece" />
<TextView
android:id="#+id/tv_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sep2"
android:gravity="center"
android:padding="10dp"
android:text="Email"
android:textColor="#1D88FC"
android:textSize="20dp" />
<View
android:id="#+id/sep3"
android:layout_width="fill_parent"
android:layout_height="0.75dp"
android:layout_below="#+id/tv_email"
android:background="#cecece" />
<TextView
android:id="#+id/tv_save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sep3"
android:gravity="center"
android:padding="10dp"
android:text="Save"
android:textColor="#1D88FC"
android:textSize="20dp" />
<View
android:id="#+id/sep4"
android:layout_width="fill_parent"
android:layout_height="0.75dp"
android:layout_below="#+id/tv_save"
android:background="#cecece" />
<TextView
android:id="#+id/tv_no_thanks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sep4"
android:gravity="center"
android:padding="10dp"
android:text="No Thanks"
android:textColor="#1D88FC"
android:textSize="20dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_bottom"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/frame"
android:visibility="visible" >
<TextView
android:id="#+id/tv_twiter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="10dp"
android:text="Info"
android:textColor="#000000"
android:textSize="16dp" />
<View
android:id="#+id/sep1"
android:layout_width="fill_parent"
android:layout_height="0.75dp"
android:layout_below="#+id/tv_twiter"
android:background="#cecece" />
<TextView
android:id="#+id/tv_facebook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sep1"
android:gravity="left"
android:padding="10dp"
android:text="Ead one Eno"
android:textColor="#1D88FC"
android:textSize="16dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bottom_nav_bg"
android:visibility="visible" >
<ImageView
android:id="#+id/iv_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/play_btn" />
<ImageView
android:id="#+id/iv_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/about_us" />
<ImageView
android:id="#+id/iv_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/share_icon" />
</RelativeLayout>
</RelativeLayout>
AdapterViewFlipper would be the best way to go since, in a ViewFlipper you need to pre define the views.
Inside onCreate :
ArrayList<String> urls;
//Fetch and set urls to this ArrayList;
AdapterViewFlipper flipper = (AdapterViewFlipper) findViewById(R.id.flipper);
flipper.setAdapter(new FlipperAdapter(urls));
FlipperAdapter.java
For loading image from urls, I'd suggest the use of the Universal Image Loader library : https://github.com/nostra13/Android-Universal-Image-Loader
public class FlipperAdapter extends BaseAdapter {
ArrayList<String> urls;
public FlipperAdapter(ArrayList<String> urls) {
this.urls = urls;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return urls.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return urls.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = (LinearLayout) LayoutInflater.inflate(
R.layout.viewLayout, parent, false);
}
ImageView image = (ImageView) convertView.findViewById(R.id.image);
imageLoader.displayImage(urls.get(position), image, null);
return convertView;
}
}
Edit 1 : viewLayout.xml (This will contain the layout of the items you want to display inside the adapterViewFlipper)
<?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">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>