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(); }
}
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 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);
I have made a small program in which i have used one button and a WebView. WebView visibility is set GONE
and when i press the button 1st time i want to set visibility to visible and when i press the button 2nd time i want the visibility to be GONE. It should do the same thing consecutively. I have tried to make it work using if ..else and with switch .Its strange that if you click the button a lot of times (depending , it can be 3 or 7 or 9 or even more times) the code start to work.
Please help me.
Here is my code:
public class MyMenu extends Activity {
Button info;
WebView webView;
int see=0 ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_menu);
info = (Button) findViewById(R.id.info);
webView = (WebView) findViewById(R.id.webView1);
webView.setVisibility(View.GONE);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl("file:///android_asset/odigies.html");
// make listener for odigies button
info.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (see == 0) {
webView.setVisibility(View.VISIBLE);
see = 1;
} else {
webView.setVisibility(View.GONE);
see = 0;
}
}
});
}
//send app with sms
public void send(View v){
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "Δωρεάν καλή εφαρμογή για Λοττο,τζοκερ,κινο και προτο.https://play.google.com/store/apps/details?id=o.tzogadoros");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
}
//send app with email
public void email(View v){
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.fromParts("mailto",
"", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Εφαρμογή Lotto Android");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Δωρεάν καλή εφαρμογή για Λοττο,τζοκερ,κινο και προτο.Δίνει τυχαίους αριθμούς για τα τυχαιρά παιχνίδια. ");
if (emailIntent.resolveActivity(getPackageManager()) == null) {
Toast.makeText(getApplicationContext(),
"Παρακαλώ παραμετροποίησε τον λογοριασμό email σου", Toast.LENGTH_LONG)
.show();
} else {
// Secondly, use a chooser will gracefully handle 0,1,2+ matching
// activities
startActivity(Intent.createChooser(emailIntent,
"Διάλεξε το email σου"));
}
}
// go to tzoker activity
public void tzoker(final View view) {
startActivity(new Intent(this, Tzoker.class));
}
// go to kino activity
public void kino(final View view) {
startActivity(new Intent(this, Kino.class));
}
// go to lotto activity
public void lotto(final View view) {
startActivity(new Intent(this, MainActivity.class));
}
// go to proto activity
public void proto(final View view) {
startActivity(new Intent(this, Proto.class));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_menu, menu);
return true;
}
}
and the xml file:
<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="#eaf39b"
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=".MyMenu" >
<ScrollView
android:id="#+id/vertical_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<HorizontalScrollView
android:id="#+id/horizontal_scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eaf39b"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eaf39b"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="lotto"
android:src="#drawable/lottoicon" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="tzoker"
android:src="#drawable/tzokericon" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="kino"
android:src="#drawable/kinoicon" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="proto"
android:src="#drawable/protoicon" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/menuicon" />
</LinearLayout>
<Button
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="#string/Menuodigies"
android:textSize="22sp"
android:textStyle="bold" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/sendsms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="send"
android:text="#string/sms"
android:textSize="22sp"
android:textStyle="bold" />
<Button
android:id="#+id/sendemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="email"
android:text="#string/email"
android:textSize="22sp"
android:textStyle="bold" />
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
Finally when the webview appear there is no zoom controls,why?
Thanks for your time.
Is it better with that ?
#Override
public void onClick(View v) {
if (webView.getVisibility==View.GONE) {
webView.setVisibility(View.VISIBLE);
} else {
webView.setVisibility(View.GONE);
}
}
I am using Vuforia AR sdk and want to create a button on the camera preview on the screen.
I cannot figure out where and how to add the button.
I have edit the camera_overlay_udt.xml like this.. In my layout design i have placed back button and listview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:src="#drawable/back" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Swipart"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/arcstarButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"
android:src="#drawable/star_button" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/favListingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:gravity="top"
android:orientation="horizontal"
android:visibility="visible" >
<ListView
android:id="#+id/favlist"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:layout_marginLeft="7dp"
android:cacheColorHint="#00000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#color/overlay_bottom_bar_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1" >
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/overlay_bottom_bar_separators" />
<ImageButton
android:id="#+id/camera_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:contentDescription="#string/content_desc_camera_button"
android:onClick="onCameraClick"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/camera_button_background" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/bottom_bar"
android:background="#color/overlay_bottom_bar_separators" />
</RelativeLayout>
after that please Edit that ImageTargets.java class
private void addOverlayView(boolean initLayout) {
// Inflates the Overlay Layout to be displayed above the Camera View
LayoutInflater inflater = LayoutInflater.from(this);
mUILayouts = (RelativeLayout) inflater.inflate(
R.layout.camera_overlay_udt, null, false);
mUILayouts.setVisibility(View.VISIBLE);
// If this is the first time that the application runs then the
// uiLayout background is set to BLACK color, will be set to
// transparent once the SDK is initialized and camera ready to draw
if (initLayout) {
mUILayouts.setBackgroundColor(Color.TRANSPARENT);
}
// Adds the inflated layout to the view
addContentView(mUILayouts, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Gets a reference to the bottom navigation bar
mBottomBar = mUILayouts.findViewById(R.id.bottom_bar);
// Gets a reference to the Camera button
mCameraButton = mUILayouts.findViewById(R.id.camera_button);
mCameraButton.setVisibility(View.GONE);
favButton = (ImageButton) mUILayouts.findViewById(R.id.arcstarButton);
listview = (ListView) mUILayouts.findViewById(R.id.favlist);
backButton = (ImageButton) mUILayouts.findViewById(R.id.backButton);
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
finish();
}
});
listview.setVisibility(View.GONE);
galleryList = SendFile.getFavourites();
if (galleryList != null) {
gridviewAdapter = new GridviewAdapter(ImageTargets.this);
listview.setAdapter(gridviewAdapter);
}
favButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (galleryList != null && galleryList.size() > 0) {
if (listview.getVisibility() == View.GONE) {
listview.setVisibility(View.VISIBLE);
} else {
listview.setVisibility(View.GONE);
}
} else {
Toast.makeText(ImageTargets.this, "Favourites not fond",
Toast.LENGTH_LONG).show();
}
}
});
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paramAdapterView,
View paramView, int positon, long paramLong) {
SendFile.setFavourite(galleryList.get(positon));
Intent intent = new Intent(ImageTargets.this,
LoadingScreen.class);
Bundle bundle = new Bundle();
bundle.putInt("x", x_Axis);
bundle.putInt("y", y_Axis);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
});
showDialogHandler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Server Response: " + aResponse, Toast.LENGTH_SHORT)
.show();
showAlertDialog(aResponse);
} else {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Not Got Response From Server.", Toast.LENGTH_SHORT)
.show();
}
};
};
loadingDialogHandler.captureButtonContainer = mUILayouts
.findViewById(R.id.camera_button);
mUILayouts.bringToFront();
}
They showing there layouts using handlers
Start you camera preview in a normal way. Place a layout on top of it with transparent background like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ff000000"
android:layout_height="match_parent">
<ImageView
android:id="#+id/start_image_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:src="#drawable/scan_image"/>
</RelativeLayout>
In java file, you can add this layout like this:
private View mStartupView;
mStartupView = getLayoutInflater().inflate(
R.layout.startup_screen, null);
// Add it to the content view:
addContentView(mStartupView, new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
This way you will get to see your button on top of camera preview. Hope it helps
You can add buttons in cameraoverlay layout which is in layout folder and you can initialize buttons in initAR function which is in mainactivity.
Step 1: Add the button in the camera_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
style="#android:style/Widget.ProgressBar"
android:id="#+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="51dp"
android:text="Button" />
</RelativeLayout>
Step 2: Edit the ImageTargets.java class
private static final String LOGTAG = "ImageTargets";
private Button b1;
Step 3: Modify the initApplicationAR() function of ImageTargets.java class
private void initApplicationAR()
{
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = Vuforia.requiresAlpha();
mGlView = new SampleApplicationGLView(this);
mGlView.init(translucent, depthSize, stencilSize);
mRenderer = new ImageTargetRenderer(this, vuforiaAppSession);
mRenderer.setTextures(mTextures);
mGlView.setRenderer(mRenderer);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
b1.setVisibility(View.GONE);
}
});
}
Now lay back and watch your button disappear on a click!
Although it's a long time since the post.. yet I found one article.. wherein you can have the desired thing..
Ref: https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82
Solution:
Step1: Make a custom layout XML file (vuforia_widget_screen.xml). For example, button has been added.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<FrameLayout
android:id="#+id/unity_player_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:text="#string/welcome" />
</FrameLayout>
Step 2: Make following changes in the UnityPlayerActivity.java
Replace "setContentView(mUnityPlayer);" with
setContentView(R.layout.vuforia_widget_screen);
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.addView(mUnityPlayer.getView());
-> For anyone, who will face the issue in future. :)
I have 2 layouts in my activity, if clicked on ImageView "show" from 1st layout, 2nd layout should display, but here its not happening so, had given the coding correcting but could not solve this issue
Here's my code
public class About extends Activity {
LinearLayout line1, line2;
ImageView show;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
line1=(LinearLayout) findViewById(R.id.ll1);
line2=(LinearLayout)findViewById(R.id.ll2);
show=(ImageView)findViewById(R.id.ss);
show.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
show.setVisibility(View.VISIBLE);
// TODO Auto-generated method stub
line1.setVisibility(View.VISIBLE);
if (line2.getVisibility() == View.INVISIBLE || line2.getVisibility() == View.GONE) {
line2.setVisibility(View.VISIBLE); }
else {
line2.setVisibility(View.INVISIBLE);
}
}
});
Xml Layout
<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"
android:background="#color/black" >
<LinearLayout
android:id="#+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<ImageView
android:id="#+id/ss"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/menu"
android:clickable="true" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_width="199dp"
android:layout_height="wrap_content"
android:background="#color/black"
android:layout_toRightOf="#+id/ll1"
android:visibility="gone"
>
<ImageView
android:id="#+id/about"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="#+id/textView1"
android:layout_toLeftOf="#+id/jobs"
android:src="#drawable/about" />
<ImageView
android:id="#+id/jobs"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/jobs" />
<ImageView
android:id="#+id/log"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/log" />
<ImageView
android:id="#+id/home"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/home" />
</LinearLayout>
</RelativeLayout>
For your image view 'ss' in xml, set property android:clickable="true".
Or better otherwise, use an ImageButton in place of ImageView in your xml
EDIT -
Change this
show=(ImageView)findViewById(R.id.ss);
to
show=(ImageView)findViewById(R.id.show);
You have wrongly defined the id of your ImageView that is why you are not able to get the onClick event of your ImageView.
Change the id of your ImageView to R.id.show besides R.id.ss as below:
Change this
show=(ImageView)findViewById(R.id.ss);
to
show=(ImageView)findViewById(R.id.show);
EDITED:
Try to show and hide your layout as below in your onClick listener.
if (line2.getVisibility() == View.INVISIBLE || line2.getVisibility() == View.GONE) {
line2.setVisibility(View.VISIBLE);
line1.setVisibility(View.INVISIBLE);
}
else {
line2.setVisibility(View.INVISIBLE);
line1.setVisibility(View.VISIBLE);
}