I have three RecyclerViews, and all three are lagging in scroll. I have tried many things suggested on the internet, but nothing made my RecyclerView faster.
I have tried the solutions given below,
RecyclerView laggy scrolling
Extremely Laggy RecyclerView Performance
Lags when RecyclerView scrolling
And some more. Some of them are not relevant. But still, it lags.
For the reference, below are the images for RecyclerView items.
The xml of the view (for the single chat bubble). It's almost same as WhatsApp.
<LinearLayout
android:id="#+id/transactionOut"
android:layout_width="#dimen/dp300"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
android:layout_gravity="end"
android:paddingStart="0dp"
android:paddingLeft="0dp"
android:paddingEnd="13dp"
android:paddingRight="13dp"
android:clickable="true"
android:background="#drawable/outgoing_chat_bubble">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:minWidth="#dimen/dp100"
android:orientation="horizontal"
android:elevation="#dimen/general_margin_or_padding_very_small"
android:padding="#dimen/dp10">
<ImageView
android:id="#+id/transactionImageOut"
android:layout_margin="#dimen/dp4"
android:layout_width="#dimen/size_transaction"
android:layout_height="#dimen/size_transaction"
android:padding="3dp"
android:visibility="gone"
android:src="#drawable/ic_transaction_indication_sent"
android:layout_gravity="center_vertical"
android:contentDescription="#string/payment_sent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:gravity="center"
android:textSize="#dimen/general_for_all"
android:text="–"
android:textColor="#color/app_font_detail_color"/>
<style.views.CustomTextView
android:id="#+id/transactionAmountOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/progress_loading"
android:textColor="#color/app_font_detail_color"
android:layout_marginLeft="#dimen/dp4"
android:layout_marginStart="#dimen/dp4"
android:ellipsize="end"
android:maxLines="1"
android:textSize="#dimen/general_for_all"
appUI:font="#string/appNormalFontName"/>
</LinearLayout>
<View
android:id="#+id/separatorMessageOut"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:visibility="gone"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginEnd="#dimen/general_margin_or_padding_very_small"
android:layout_marginRight="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:background="#color/app_font_detail_color"/>
<LinearLayout
android:id="#+id/layoutMessageOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:visibility="gone"
android:paddingTop="#dimen/general_margin_or_padding_very_small"
android:paddingBottom="#dimen/general_margin_or_padding_very_small">
<ImageView
android:layout_width="#dimen/size_extra_icon"
android:layout_height="#dimen/size_extra_icon"
android:layout_marginTop="#dimen/icon_margin_top"
android:src="#drawable/ic_sms"
android:layout_marginStart="#dimen/general_margin_or_padding_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_small"
android:visibility="visible"
android:contentDescription="#string/design"/>
<TextView
android:id="#+id/textMessageOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:textColor="#color/app_font_detail_color"
android:text="Text message"/>
</LinearLayout>
<View
android:id="#+id/separatorNoteOut"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:visibility="gone"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginEnd="#dimen/general_margin_or_padding_very_small"
android:layout_marginRight="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:background="#color/app_font_detail_color"/>
<LinearLayout
android:id="#+id/layoutNoteOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:visibility="gone"
android:paddingTop="#dimen/general_margin_or_padding_very_small"
android:paddingBottom="#dimen/general_margin_or_padding_very_small">
<ImageView
android:layout_width="#dimen/size_extra_icon"
android:layout_height="#dimen/size_extra_icon"
android:layout_marginTop="#dimen/icon_margin_top"
android:src="#drawable/ic_notes"
android:layout_marginStart="#dimen/general_margin_or_padding_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_small"
android:visibility="visible"
android:contentDescription="#string/design"/>
<TextView
android:id="#+id/textNoteOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:textColor="#color/app_font_detail_color"
android:text="Text note"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/app_font_detail_color"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginEnd="#dimen/general_margin_or_padding_very_small"
android:layout_marginRight="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="#dimen/dp6">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start|center_vertical">
<style.views.CircleImageView
android:id="#+id/bankLogoOut"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:src="#drawable/placeholder_default"
appUI:circular_border_color="#color/profile_border_color"
appUI:circular_border_width="#dimen/dp1" />
<TextView
android:id="#+id/bankNameOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:maxLines="1"
android:ellipsize="end"
android:text="#string/progress_loading"
android:textSize="#dimen/small_size" />
</LinearLayout>
<ImageView
android:id="#+id/showDetailImageOut"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/dp4"
android:layout_marginEnd="#dimen/dp4"
android:src="#drawable/ic_transaction_more"
android:contentDescription="#string/more"/>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="#+id/messageStatusImageOut"
android:layout_width="#dimen/size_transaction"
android:layout_height="#dimen/size_transaction"
android:layout_centerVertical="true"
android:src="#drawable/ic_pending"
android:layout_marginStart="#dimen/general_margin_or_padding_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_small"
android:visibility="visible"
android:contentDescription="#string/design"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
<style.views.CustomTextView
android:id="#+id/transactionDatetimeOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="end"
android:text="#string/account"
android:textColor="#color/app_font_detail_color"
android:textSize="#dimen/date_time_stamp"
android:layout_toLeftOf="#+id/messageStatusImageOut"
android:layout_toStartOf="#+id/messageStatusImageOut" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Here is it's adapter
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
holder.setIsRecyclable(false);
if (holder instanceof HeaderViewHolder) {
HeaderViewHolder transactionViewHolder = (HeaderViewHolder) holder;
String getTodayDate = (String) filteredList.get(position);
transactionViewHolder.setDate(DateUtility.getFormattedDate(getTodayDate));
} else if (holder instanceof MainViewHolder) {
MainViewHolder viewHolder = (MainViewHolder) holder;
try {
final History history = (History) filteredList.get(position);
viewHolder.setTransaction(history, mContext);
} catch (Exception e){
e.printStackTrace();
}
}
}
And the setTransaction method of ViewHolder
private void setTransaction(final History history, final Context context){
String myId = new Session(context).getStringForKey(Session.prIdKey);
if(history.getTo().equals(history.getFrom())) {
transactionSelf.setVisibility(View.VISIBLE);
transactionOut.setVisibility(View.GONE);
transactionIn.setVisibility(View.GONE);
transactionAmountSelf.setText(Utils.parseIntoPKR(history.getAmount()));
transactionDateTimeSelf.setText(DateUtility.getTimeFromEpoch(history.getEpoch()));
messageStatusImageSelf.setVisibility(View.VISIBLE);
switch (history.getStatus()) {
case Constants.STATUS_PENDING:
messageStatusImageSelf.setImageResource(R.drawable.ic_pending);
break;
case Constants.STATUS_FAILED:
messageStatusImageSelf.setImageResource(R.drawable.ic_transaction_status_blocked);
break;
default:
messageStatusImageSelf.setImageResource(R.drawable.ic_transaction_status_done);
break;
}
LinkedBank associatedBank = history.getSenderBank();
bankNameSelf.setText(associatedBank.fetchAbbreviationAndAccountNumber());
if(history.getReceiverNotes() != null && history.getReceiverNotes().length() > 0) {
separatorNoteSelf.setVisibility(View.VISIBLE);
layoutNoteSelf.setVisibility(View.VISIBLE);
textNoteSelf.setText(history.getReceiverNotes());
} else if(history.getSenderNotes() != null && history.getSenderNotes().length() > 0) {
separatorNoteSelf.setVisibility(View.VISIBLE);
layoutNoteSelf.setVisibility(View.VISIBLE);
textNoteSelf.setText(history.getSenderNotes());
}
transactionSelf.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((OnIndividualTransactionSelection) context).onTransactionSelected(history);
}
});
} else if(history.getFrom().equals(myId)) {
//from my number -> cash out
transactionOut.setVisibility(View.VISIBLE);
transactionIn.setVisibility(View.GONE);
transactionSelf.setVisibility(View.GONE);
if(history.getMessage() != null && history.getMessage().length() > 0) {
separatorMessageOut.setVisibility(View.VISIBLE);
layoutMessageOut.setVisibility(View.VISIBLE);
textMessageOut.setText(history.getMessage());
}
if(history.getSenderNotes() != null && history.getSenderNotes().length() > 0) {
separatorNoteOut.setVisibility(View.VISIBLE);
layoutNoteOut.setVisibility(View.VISIBLE);
textNoteOut.setText(history.getSenderNotes());
}
messageStatusImageOut.setVisibility(View.VISIBLE);
switch (history.getStatus()) {
case Constants.STATUS_PENDING:
messageStatusImageOut.setImageResource(R.drawable.ic_pending);
break;
case Constants.STATUS_FAILED:
messageStatusImageOut.setImageResource(R.drawable.ic_transaction_status_blocked);
break;
default:
messageStatusImageOut.setImageResource(R.drawable.ic_transaction_status_done);
break;
}
transactionAmountOut.setText(Utils.parseIntoPKR(history.getAmount()));
transactionDatetimeOut.setText(DateUtility.getTimeFromEpoch(history.getEpoch()));
LinkedBank associatedBank = history.getSenderBank();
bankNameOut.setText(associatedBank.fetchAbbreviationAndAccountNumber());
Picasso.with(context).load(associatedBank.getBankLogo()).placeholder(R.drawable.placeholder_default).error(R.drawable.placeholder_default).into(bankLogoOut);
transactionOut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((OnIndividualTransactionSelection) context).onTransactionSelected(history);
}
});
} else if(history.getTo().equals(myId)) {
transactionIn.setVisibility(View.VISIBLE);
transactionOut.setVisibility(View.GONE);
transactionSelf.setVisibility(View.GONE);
if(history.getMessage() != null && history.getMessage().length() > 0) {
separatorMessageIn.setVisibility(View.VISIBLE);
layoutMessageIn.setVisibility(View.VISIBLE);
textMessageIn.setText(history.getMessage());
}
if(history.getReceiverNotes() != null && history.getReceiverNotes().length() > 0) {
separatorNoteIn.setVisibility(View.VISIBLE);
layoutNoteIn.setVisibility(View.VISIBLE);
textNoteIn.setText(history.getReceiverNotes());
}
transactionAmountIn.setText(Utils.parseIntoPKR(history.getAmount()));
transactionDatetimeIn.setText(DateUtility.getTimeFromEpoch(history.getEpoch()));
LinkedBank associatedBank = history.getReceiverBank();
bankNameIn.setText(associatedBank.fetchAbbreviationAndAccountNumber());
Picasso.with(context).load(associatedBank.getBankLogo()).placeholder(R.drawable.placeholder_default).error(R.drawable.placeholder_default).into(bankLogoIn);
transactionIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((OnIndividualTransactionSelection) context).onTransactionSelected(history);
}
});
}
}
It's answer may help me to optimize the other two RecyclerViews as well. Any help is highly appreciated.
Two quick tips
1) You might want to cut down on a lots o processing while it's still scrolling. This will improve scrolling performance substantially
2) You might want to relook at this and similar 'new' later, allocating on every bind will slow down your scroll.
String myId = new Session(context).getStringForKey(Session.prIdKey);
Related
Basically, I want to have an AlertDialog in which multiple images will load on the same ImageView. By clicking the NEXT button it will get the next image bitmap from bitmap list and finally will load on that ImageView. Same case for PREV button. It will take previous bitmap and will load the image on the same ImageView.
But the problem is after loading the first image it does not load the next image. If I click the next button then it takes the next bitmap but the imageview.setImageBitmap(bitmap) does not work.
How to remove or clear the previous image to place the next photos?
The XML file are given below :
<?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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/question"
android:gravity="center"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:text="#string/question"
android:textSize="14sp"
android:textColor="#color/light_black"/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/divider"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/selected_place_images"
android:scaleType="centerCrop"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/divider"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="47dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/previous"
android:text="#string/previous_page"
android:textColor="#color/black"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/next"
android:text="#string/next_page"
android:textColor="#color/black"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
The java code are given below :
private void showDialogOfImages() {
Log.d(TAG,"showDialogOfImages : showing places images");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = this.getLayoutInflater();
View customLayout = inflater.inflate(R.layout.custom_displaying_selected_place_images,null);
mSelectedPlaceImages = (ImageView) customLayout.findViewById(R.id.selected_place_images);
nextPage = (TextView) customLayout.findViewById(R.id.next);
previousPage = (TextView) customLayout.findViewById(R.id.previous);
displayPhoto();
nextPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentPhotoIndex++;
displayPhoto();
}
});
previousPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentPhotoIndex--;
displayPhoto();
}
});
builder.setView(customLayout);
builder.show();
}
private void displayPhoto() {
if (mCurrentPhotoIndex < mSelectedLocationPhotosBitmap.size()) {
Bitmap bitmap = mSelectedLocationPhotosBitmap.get(mCurrentPhotoIndex);
Toast.makeText(context,""+mCurrentPhotoIndex+" : "+bitmap,Toast.LENGTH_LONG).show();
mSelectedPlaceImages.setImageBitmap(bitmap);
setButtonVisibility();
}
}
private void setButtonVisibility() {
if(mCurrentPhotoIndex == 0 && mSelectedLocationPhotosBitmap.size() == 1){
nextPage.setEnabled(false);
nextPage.setClickable(false);
nextPage.setTextColor(getResources().getColor(R.color.divider));
previousPage.setEnabled(false);
previousPage.setClickable(false);
previousPage.setTextColor(getResources().getColor(R.color.divider));
}
else if (mCurrentPhotoIndex == 0 && mSelectedLocationPhotosBitmap.size() > 1){
nextPage.setEnabled(true);
nextPage.setClickable(true);
nextPage.setTextColor(getResources().getColor(R.color.black));
previousPage.setEnabled(false);
previousPage.setClickable(false);
previousPage.setTextColor(getResources().getColor(R.color.divider));
}
else if (mCurrentPhotoIndex == mSelectedLocationPhotosBitmap.size()-1 && mSelectedLocationPhotosBitmap.size() > 1){
nextPage.setEnabled(false);
nextPage.setClickable(false);
nextPage.setTextColor(getResources().getColor(R.color.divider));
previousPage.setEnabled(true);
previousPage.setClickable(true);
previousPage.setTextColor(getResources().getColor(R.color.black));
}
else{
nextPage.setEnabled(true);
nextPage.setClickable(true);
nextPage.setTextColor(getResources().getColor(R.color.black));
previousPage.setEnabled(true);
previousPage.setClickable(true);
previousPage.setTextColor(getResources().getColor(R.color.black));
}
}
You need to clear the previous image from imageview and then you can set the new on top.
Do as below
private void displayPhoto() {
if (mCurrentPhotoIndex < mSelectedLocationPhotosBitmap.size()) {
Bitmap bitmap = mSelectedLocationPhotosBitmap.get(mCurrentPhotoIndex);
Toast.makeText(context,""+mCurrentPhotoIndex+" : "+bitmap,Toast.LENGTH_LONG).show();
mSelectedPlaceImages.setImageBitmap(null)
mSelectedPlaceImages.setImageBitmap(bitmap);
setButtonVisibility();
}
}
Try this:
mSelectedPlaceImages.destroyDrawingCache();
mSelectedPlaceImages.setImageBitmap(bitmap);
mSelectedPlaceImages.buildDrawingCache();
I have Pager Adapter that initialize Fragment list. Problem is that Fragment loading very slow. It has delay of couple seconds, than start do load data.
I have parsed data from URL in AsyncTask doInBackground() and worked with UI in AsyncTask onPosteExecute()
Here is my Fragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
readBundle(getArguments());
v = inflater.inflate(R.layout.fragment_fragment1, container, false);
new asyncTekstovi().execute(result);
return v;
}
public class asyncTekstovi extends AsyncTask<String, ArrayList<String>, ArrayList<String>> {
String result;
#Override
protected ArrayList<String> doInBackground(String... params)
{
try {
result = Ion.with(getActivity().getApplicationContext())
.load(FragmentNewsReader.this.result)
.asString()
.get();
} catch (Exception e){
e.printStackTrace();
}
String pasusUTekstu="";
if (result != null){
String htmlStringTekst=result.substring(result.indexOf("<!-- BEGIN .shortcode-content -->"), result.length());
int startPositionTekst=htmlStringTekst.indexOf("<div class=\"shortcode-content\">");
int endPositionTekst=startPositionTekst+"<div class=\"shortcode-content\">".length();
while(htmlStringTekst.substring(startPositionTekst,endPositionTekst).indexOf("<!-- END .shortcode-content -->")<0){
endPositionTekst++;
}
htmlStringTekst=htmlStringTekst.substring(startPositionTekst,endPositionTekst);
//System.out.println("vladica:"+htmlStringTekst.length()+htmlStringTekst);
int poc1;
int kraj1;
while((poc1=htmlStringTekst.indexOf("<div id"))>=0){
//System.out.println("poc1="+poc1);
kraj1=poc1+"<div id".length();
while(htmlStringTekst.substring(poc1,kraj1).indexOf(">")<0){
//System.out.println("seckanje:"+htmlStringTekst.substring(poc1,kraj1));
kraj1++;
}
htmlStringTekst=htmlStringTekst.replace(htmlStringTekst.substring(poc1,kraj1),"<p>");
}
while((poc1=htmlStringTekst.indexOf("<p "))>=0){
kraj1=poc1+"<p ".length();
while(htmlStringTekst.substring(poc1,kraj1).indexOf(">")<0){
kraj1++;
}
htmlStringTekst=htmlStringTekst.replace(htmlStringTekst.substring(poc1,kraj1),"<p>");
}
htmlStringTekst=htmlStringTekst.replace("<div id","<p>");
htmlStringTekst=htmlStringTekst.replace("</div>","</p>");
htmlStringTekst=htmlStringTekst.replace(" ","");
while(htmlStringTekst.length()>0){
startPositionTekst=htmlStringTekst.indexOf("<p>");
if(startPositionTekst>=0){
startPositionTekst+="<p>".length();
endPositionTekst=startPositionTekst;
while (htmlStringTekst.substring(startPositionTekst, endPositionTekst).indexOf("</p>") < 0) {
endPositionTekst++;
}
if(pasusUTekstu.indexOf("<img")<0) {
if(pasusUTekstu.length()>5) pasusUTekstu+="\n\n";
pasusUTekstu += htmlStringTekst.substring(startPositionTekst, endPositionTekst); //e sad ja...
}
else {
pasusUTekstu=htmlStringTekst.substring(startPositionTekst,endPositionTekst);
}
htmlStringTekst = htmlStringTekst.substring(endPositionTekst);
pasusUTekstu = pasusUTekstu.replace("<strong>", "");
pasusUTekstu = pasusUTekstu.replace("</strong>", "");
int poc=pasusUTekstu.indexOf("<img");
int zastavica=0;
if(poc>=0) zastavica=1;
while(poc>=0) {
int kraj = poc;
while (pasusUTekstu.substring(poc, kraj).indexOf("/>") < 0) {
kraj++;
}
String link = pasusUTekstu.substring(poc, kraj);
pasusUTekstu = pasusUTekstu.replace(link, "");
poc = pasusUTekstu.indexOf("<img");
}
poc=pasusUTekstu.indexOf("<a href=");
while(poc>=0) {
int kraj = poc;
while (pasusUTekstu.substring(poc, kraj).indexOf(">") < 0) {
kraj++;
}
String link = pasusUTekstu.substring(poc, kraj);
pasusUTekstu = pasusUTekstu.replace(link, "");
poc = pasusUTekstu.indexOf("<a href=");
}
pasusUTekstu=pasusUTekstu.replace("&","&");
pasusUTekstu=pasusUTekstu.replace("–","-");
pasusUTekstu=pasusUTekstu.replace("“","\"");
pasusUTekstu=pasusUTekstu.replace("”","\"");
pasusUTekstu=pasusUTekstu.replace("<p>","");
pasusUTekstu=pasusUTekstu.replace("</a>","");
pasusUTekstu=pasusUTekstu.replace("<br />","");
pasusUTekstu=pasusUTekstu.replace("</p>","");
pasusUTekstu=pasusUTekstu.replace(" ","");
pasusUTekstu=pasusUTekstu.replace("\n\n\n","\n");
//pasusUTekstu=pasusUTekstu.replace("\n\n","\n");
//System.out.println("pocetak je:"+ pasusUTekstu);
if(zastavica==1) {
if(pasusUTekstu.substring(pasusUTekstu.length()-2).equals("\n\n")) pasusUTekstu=pasusUTekstu.substring(0,pasusUTekstu.length()-2);
listaTeksta.add(pasusUTekstu);
pasusUTekstu="";
zastavica=0;
}
}
else break;
}
}
if(pasusUTekstu.length()>5) listaTeksta.add(pasusUTekstu);
return listaTeksta;
}
#Override
protected void onPostExecute(ArrayList<String> result) {
String rezultat = "";
for(int i=0;i<listaSlika.size() ;i++) {
v.findViewById(mLayoutIdArray[i]).setVisibility(View.VISIBLE);
}
for(int i=0;i<result.size();i++) {
textTv[i] = (TextView) v.findViewById(nizTekstaID[i]);
textTv[i].setText(result.get(i));
}
}
protected void onPreExecute() {
}
}
Here is my XML:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/vestGlavnaSlikaLayout"
android:layoutDirection="ltr"
android:elevation="10dp">
<ImageView
android:id="#+id/glavnaSlika"
android:layout_width="match_parent"
android:fitsSystemWindows="false"
android:scaleType="fitXY"
android:focusable="false"
android:cropToPadding="false"
android:adjustViewBounds="true"
android:layout_alignParentBottom="false"
android:layout_alignParentRight="false"
android:layout_alignParentEnd="false"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/layouttekstglavnevesti1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:drawable/screen_background_dark_transparent"
android:padding="0dp">
<TextView
android:id="#+id/naslovglavni"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:padding="10dp"
android:textColor="#android:color/background_light"
android:textSize="36sp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/lazoutZaNaslove"
android:layout_marginBottom="15dp"
android:layout_marginLeft="#dimen/h"
android:layout_marginRight="#dimen/h"
android:layout_marginTop="-10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/prednaslov"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#android:color/darker_gray"
android:layout_marginLeft="-40dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/naslov1"
android:textSize="20sp"
android:textColor="#android:color/black"
android:textStyle="normal|bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/podnaslov"
android:textColor="#android:color/black"
android:textSize="15sp"
android:textStyle="normal|bold" />
</LinearLayout>
<include
layout="#layout/activity_slikatext1"
android:id="#+id/includedLayout"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/h"
android:layout_marginRight="#dimen/h"
android:layout_below="#id/lazoutSlikaTekst" />
<include
layout="#layout/activity_slikatext2"
android:id="#+id/includedLayout1"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/h"
android:layout_marginRight="#dimen/h"
android:layout_below="#id/includedLayout" />
<include
layout="#layout/activity_slikatext3"
android:id="#+id/includedLayout2"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/h"
android:layout_marginRight="#dimen/h"
android:layout_below="#id/includedLayout1" />
<include
layout="#layout/activity_slikatext4"
android:id="#+id/includedLayout3"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/h"
android:layout_marginRight="#dimen/h"
android:layout_below="#id/includedLayout2" />
<include
layout="#layout/activity_slikatext5"
android:id="#+id/includedLayout4"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/h"
android:layout_marginRight="#dimen/h"
android:layout_below="#id/includedLayout3" />
Change this code to onViewCreated() method
new asyncTekstovi().execute(result);
My multiple youtube videos in viewPager overlaying itself and youtubePlayer stops after one second recording. My first video works fine, but whenever I slide to another or back to previous one and try to record it I give an overlaying error. I try to set the videoContainer to gone, release the youtube player, bringToFront() current videoContainer, hide/show detach/attach videoFragment and the problem still remains.The detach/attach fragment solution works but not every time.
My warn message: YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.widget.LinearLayout{54f27e3 V.E...... ........ 0,0-1080,1584 #7f1000ec app:id/globalViewLinearLayout}. Right edge 50 px right of YouTubePlayerView's left edge.
My FragmentViewPagerItemXML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/globalViewLinearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundContent">
<com.app.CustomScrollView
android:id="#+id/customScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollViewLinearLayout">
<FrameLayout
android:id="#+id/mediaContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_marginBottom="80dp"
android:visibility="gone"
android:id="#+id/videoContainerLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/videoContainer"
android:orientation="vertical" />
</LinearLayout>
<RelativeLayout
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="#dimen/imageHeight"
android:id="#+id/galleryContainer"
android:layout_marginBottom="55dp">
<ProgressBar
android:id="#+id/progress"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:id="#+id/photoWithButtonsContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#color/black">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/themePhoto"
android:clickable="true"
android:adjustViewBounds="true"
android:padding="10dp"
android:background="#android:color/white"
android:layout_centerInParent="true"
android:visibility="gone" />
<ImageButton
android:layout_alignRight="#+id/themePhoto"
android:layout_alignTop="#+id/themePhoto"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_margin="8dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#drawable/expand"
android:id="#+id/zoomMe"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_gravity="bottom|right"
android:id="#+id/buttonLinearLayout">
<android.support.design.widget.FloatingActionButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/playButton"
android:src="#drawable/ic_play_arrow_black_48dp"
app:backgroundTint="#color/white"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:visibility="gone" />
<android.support.design.widget.FloatingActionButton
app:backgroundTint="#color/white"
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/videoButton"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:src="#drawable/ic_ondemand_video_black_48dp"
android:visibility="gone" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_height="85dp"
android:background="#drawable/ribbon"
android:id="#+id/artWorkCounter"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
</FrameLayout>
Code:
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
videoContainer = (LinearLayout) view.findViewById(R.id.videoContainerLayout);
mYouTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
return view;
}
viewHolder.videoButton = (FloatingActionButton) view.findViewById(R.id.videoButton);
viewHolder.videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view1) {
if (view.findViewById(R.id.videoContainer).isShown()) {
animateFab(false);
videoContainer.setVisibility(View.GONE);
} else {
if (context instanceof TestActivity)
((TestActivity) context).setAutoOrientationEnabled(true);
youTubeVideoInit(artWork.getVideo_uri(), view);
animateFab(true);
}
}
});
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (viewHolder != null) {
if (!isVisibleToUser ) {
isVisible = false;
if (videoContainer != null)
if (videoContainer.isShown()) {
viewHolder.videoButton.performClick();
}
if(mYouTubePlayerFragment!=null)
getChildFragmentManager().beginTransaction().detach(mYouTubePlayerFragment).commitAllowingStateLoss();
} else {
if(mYouTubePlayerFragment!=null)
getChildFragmentManager().beginTransaction().attach(mYouTubePlayerFragment).commitAllowingStateLoss();
isVisible = true;
}
}
}
YouTubePlayer mPlayer;
YouTubePlayerSupportFragment mYouTubePlayerFragment;
String youtubeID;
LinearLayout videoContainer;
public void youTubeVideoInit(String youtubeUrl, final View view) {
final String API_KEY = getString(R.string.develop_key);
Uri uri = Uri.parse(youtubeUrl);
try {
youtubeID = URLDecoder.decode(uri.getQueryParameter("v"), "UTF-8");
} catch (UnsupportedEncodingException exception) {
exception.printStackTrace();
}
mYouTubePlayerFragment.initialize(API_KEY, new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean isRejected) {
if (!isRejected) {
mPlayer = youTubePlayer;
mPlayer.cueVideo(youtubeID);
mPlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
#Override
public void onFullscreen(boolean b) {
if (!b && context instanceof TestActivity){
((TestActivity) context).setPortraitOrientation();
((TestActivity) context).setAutoOrientationEnabled(true);
}
}
});
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
getChildFragmentManager().beginTransaction().replace(R.id.videoContainer, mYouTubePlayerFragment, YouTubePlayerFragment.class.getSimpleName()).commit();
videoContainer.setVisibility(View.VISIBLE);
}
EDIT: I found what is the problem: The Zoom-out page transformer overlays the videos.
I just do my project but when I test my app I found that then I touch the screen by using more than one fingers my app may start two or three different activities.
The activities all go to the back stack. Is this a bug in Android framework? But I can't reappear this condition, it just happened.
So, have you guys ever have this problem? Please come and discuss with me. If you do; Thanks.
Supply:
And here is My xml file , when I click the different RelativeLayout at the same time , it happened.
I tried this afternoon , but this condition is not appear anymore. Now I am confusing.
<LinearLayout android:layout_width="match_parent"
android:orientation="vertical"
android:background="#color/appDefaultSingleBlockBackground"
android:layout_height="wrap_content">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:background="#drawable/mine_bg"
android:id="#+id/mine_goto_personal_info_btn"
>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:id="#+id/mine_nick_and_avatar"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextTitle"
android:textColor="#color/appDefaultSingleBlockBackground"
android:text=""/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_interesting_venue"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_attentionbutton"
android:text="#string/myAtentionVenue"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_setting"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_setbutton"
android:text="#string/setting"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_youhuijuan"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_discountbutton"
android:text="#string/youhuijuan"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_my_rest_money"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_balancebutton"
android:text="#string/myRest"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_secure"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_accountssafebutton"
android:text="#string/secure"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/dividerdefault"
/>
</LinearLayout>
and this is my java code .
private void init(View ret) {
final TextView txtAvatar = (TextView) ret.findViewById(R.id.mine_nick_and_avatar);
final RelativeLayout gotoPersonal = (RelativeLayout) ret.findViewById(R.id.mine_goto_personal_info_btn);
RelativeLayout gotoInterest = (RelativeLayout) ret.findViewById(R.id.mine_goto_interesting_venue);
RelativeLayout gotoSetting = (RelativeLayout) ret.findViewById(R.id.mine_goto_setting);
RelativeLayout gotoYouhuijuan = (RelativeLayout) ret.findViewById(R.id.mine_goto_youhuijuan);
RelativeLayout gotoMyRestMoney = (RelativeLayout) ret.findViewById(R.id.mine_goto_my_rest_money);
RelativeLayout gotoSecure = (RelativeLayout) ret.findViewById(R.id.mine_goto_secure);
gotoPersonal.setTag("gotoPersonal");
gotoInterest.setTag("gotoInterest");
gotoSetting.setTag("gotoSetting");
gotoYouhuijuan.setTag("gotoYouhuijuan");
gotoMyRestMoney.setTag("gotoMyRestMoney");
gotoSecure.setTag("gotoSecure");
try {
Object o = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[1]);
if (o != null && !"null".equals(o)) {
txtAvatar.setText((String) o);
} else {
o = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[10]);
if (o != null && !"null".equals(o))
txtAvatar.setText("KD" + o);
}
} catch (Exception e) {
}
Object o1 = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[2]);
if (o1 != null)
MyApplication.downloader.download("http://" + o1, new ImageDownloadStateListener() {
#Override
public void loading() {
}
#Override
public void loadSuccess(Bitmap bitmap, String url) {
try {
bitmap = Tools.transforCircleBitmap(bitmap);
BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
gotoPersonal.measure(0, 0);
int measuredHeight = gotoPersonal.getMeasuredHeight();
LogHelper.print("==height" + measuredHeight);
drawable.setBounds(0, 0, measuredHeight / 5 * 4, measuredHeight / 5 * 4);
txtAvatar.setCompoundDrawables(drawable, null, null, null);
} catch (Exception e) {
//no nothing
}
}
#Override
public void loadFailed() {
}
});
gotoPersonal.setOnClickListener(this);
gotoInterest.setOnClickListener(this);
gotoSetting.setOnClickListener(this);
gotoYouhuijuan.setOnClickListener(this);
gotoMyRestMoney.setOnClickListener(this);
gotoSecure.setOnClickListener(this);
}
#Override
public void onResume() {
initActionBar();
super.onResume();
MobclickAgent.onPageStart(getClassName()); //统计页面
}
#Override
public void onPause() {
super.onPause();
MobclickAgent.onPageEnd(getClassName());
}
private String getClassName() {
String canonicalName = this.getClass().getCanonicalName();
String[] split = canonicalName.split("\\.");
return split[split.length - 1];
}
private void initActionBar() {
MyActivity activity = (MyActivity) mActivity;
activity.setActionBarLeftImg(new ColorDrawable(Color.TRANSPARENT), false);
activity.setActionBarRightImg(new ColorDrawable(Color.TRANSPARENT));
activity.setOnActionBarLeftClickListener(null);
activity.setOnActionBarRightClickListener(null);
activity.setActionBarTitle("个人中心");
}
#Override
public void onClick(View v) {
Object tag = v.getTag();
if (tag != null) {
String str = (String) tag;
if (mActivity == null) {
return;
}
if (!((MyActivity) (mActivity)).isLogin) {
Intent intent = new Intent(mActivity, LoginActivity.class);
startActivity(intent);
return;
}
if (!TextUtils.isEmpty(str))
if ("gotoPersonal".equals(str)) {
Intent intent = new Intent(mActivity, PersonalInfoActivity.class);
startActivity(intent);
} else if ("gotoInterest".equals(str)) {
Intent intent = new Intent(mActivity, VenueListActivity.class);
intent.putExtra("isInterests", true);
startActivity(intent);
} else if ("gotoSetting".equals(str)) {
Intent intent = new Intent(mActivity, SettingActivity.class);
startActivity(intent);
} else if ("gotoYouhuijuan".equals(str)) {
Intent intent = new Intent(mActivity, FavorableActivity.class);
startActivity(intent);
} else if ("gotoSecure".equals(str)) {
Intent intent = new Intent(mActivity, SecureActivity.class);
startActivity(intent);
} else if ("gotoMyRestMoney".equals(str)) {
Intent intent = new Intent(mActivity, MyRestActivity.class);
startActivity(intent);
}
}
}
You need to define the launch mode. There are at least two ways of solving this by either using the manifest file (hint: singleTop) or by using Intent flags (hint: FLAG_ACTIVITY_SINGLE_TOP).
Good luck!
Simpliest approach would be disable control that starts your Activity (button for example) after 1 click, and enable it later with some condition or action. Try it.
You can use this approach.......
((Button)findViewById(R.id.someButton)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
((Button)findViewById(R.id.someButton)).setEnabled(false);
}
});
Happy coding
I've a one ListView as shown below, when the program is first executed,then it is visible
later automatically invisible.
This layout is visible when User clicks the Button, before that the Visibility is GONE
<RelativeLayout
android:id="#+id/comments_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
android:visibility="gone" >
<TextView
android:id="#+id/comments_subHeadding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Type your comment"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/red" />
<EditText
android:id="#+id/user_commetns"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_below="#+id/comments_subHeadding"
android:layout_marginTop="5dip"
android:background="#color/white"
android:imeOptions="actionSend"
android:inputType="textLongMessage" />
</RelativeLayout>
This Layout contains ListView Here I'm facing the problem.
<LinearLayout
android:id="#+id/listview_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/comments_block"
android:background="#color/ios_blue"
android:orientation="vertical">
<ListView
android:id="#+id/comments_list1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dip"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent" >
</ListView>
</LinearLayout>
Activity Code
#Override
public void onClick(View v)
{
if (v == add_comment_button)
{
if(show)
{
comments_block.setVisibility(View.VISIBLE);
show = false;
return;
}
else
{
comments_block.setVisibility(View.GONE);
show = true;
}
}
else if (v == back_comments_button)
{ finish(); }
}
In your code you are doing
android:layout_height="wrap_content", if there are no item in listview then its height will be 0.
So please if you will use match_parent instead of wrap_content
android:layout_height="match_content"
android:layout_weight="1"
Then your listview will be visible.
I hope it will work.
I found the solution for your problem.....
You are just showing and hiding the comments_block only....
you try this one...I hope it will help you definitely...All the bset
#Override
public void onClick(View v)
{
if (v == add_comment_button)
{
if(show)
{
comments_block.setVisibility(View.VISIBLE);
listview_layout.setVisibility(View.GONE);
show = false;
return;
}
else
{
comments_block.setVisibility(View.GONE);
listview_layout.setVisibility(View.VISIBLE);
show = true;
}
}
else if (v == back_comments_button)
{ finish(); }
}