I am trying to implement card text change on Sony SmartEyeglass, but I am having trouble with the layouts. I adopted the advanced layout sample from the SDK and modified it.
I have a default xml layout that displays a title and a body text. I put 'Title' and 'Body' as default strings in the xml file, and tried to update the title and body as 'Updated' and 'Updated body text'. However, the result shows me the default layout (with 'Title' and 'Body') and the text 'Updated body text' overlapping on top of them.
Why is the title not edited, and how come the body text is on top of the xml TextView?
Here is the relevant code:
#Override
public void onResume() {
showingDetail = false;
ControlListItem item = createControlListItem(namePosition);
showLayout(item.dataXmlLayout, null);
sendListCount(item.layoutReference, quotedPeople.size());
sendListPosition(item.layoutReference, namePosition);
//utils.sendTextViewLayoutId(R.id.names_body);
sendListItem(item);
}
private ControlListItem createControlListItem(final int position) {
Log.d(Constants.LOG_TAG, "position = " + position);
ControlListItem item = new ControlListItem();
item.layoutReference = R.id.names_gallery;
item.dataXmlLayout = R.layout.smarteyeglass_quotes_names_gallery;
item.listItemId = position;
item.listItemPosition = position;
List<Bundle> list = new ArrayList<Bundle>();
// Header data
Bundle headerBundle = new Bundle();
headerBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.names_title);
headerBundle.putString(Control.Intents.EXTRA_TEXT, "Updated");
list.add(headerBundle);
// Body data
Bundle bodyBundle = new Bundle();
bodyBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.names_body);
bodyBundle.putString(Control.Intents.EXTRA_TEXT, "Updated body title");
list.add(bodyBundle);
item.layoutData = list.toArray(new Bundle[list.size()]);
return item;
}
Here is the xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="#dimen/smarteyeglass_control_width"
android:layout_height="#dimen/smarteyeglass_control_height"
tools:ignore="PxUsage,UselessParent,HardcodedText" >
<TextView
android:id="#+id/names_title"
android:layout_width="400px"
android:layout_height="30px"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginTop="5px"
android:paddingLeft="6px"
android:background="#android:color/black"
android:text="Title"
android:textColor="#android:color/white"
android:textSize="#dimen/smarteyeglass_text_size_normal" />
<View
android:id="#+id/names_divider"
android:layout_width="400px"
android:layout_height="2px"
android:layout_alignParentLeft="true"
android:layout_below="#+id/names_title"
android:background="#android:color/white" />
<TextView
android:id="#+id/names_body"
android:layout_width="400px"
android:layout_height="78px"
android:layout_marginTop="5px"
android:layout_marginLeft="10px"
android:layout_alignParentLeft="true"
android:layout_below="#+id/names_divider"
android:textColor="#android:color/white"
android:textSize="#dimen/smarteyeglass_text_size_small"
android:text="Body" />
<Gallery
android:id="#+id/names_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</Gallery>
</RelativeLayout>
we just tested your example and the text is changing fine. It looks like you might have picked the wrong XML for the gallery item. You started with smarteyeglass_layout_test_gallery instead using smarteyeglass_item_gallery.
Related
I have a spinner that allows me to not show the first item in the list, but i can set my custom prompt. However whenever the prompt text spans more than one line it is cut off at the view bounds. How can i make the spinner prompt expand to accommodate more text?
I have tried modifying the view passed into the adapter to have multiple lines and also to ellipsize at the end, but nothing works.
Images for clarity:
With one line of text,
With several lines,
This is my code:
languagesSpinner.setAdapter(new ArrayAdapter<>(EditProfileNationalityActivity.this, R.layout.no_default_spinner_item, new String[] {""}));
if(data.length>0) {
String countries = spokenLanguages.toString().substring(0, spokenLanguages.toString().length() - 2);
languagesSpinner.setPrompt(countries);
} else {
Log.e("setting prompt to default");
languagesSpinner.setPrompt("Please select languages");
}
and this is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:textColor="#android:color/black"
android:textSize="18sp"
android:ellipsize="end"
android:lines="2"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:background="?android:attr/activatedBackgroundIndicator" />
Per request, xml definition of spinner is as follows:
<com.package.views.NoDefaultSpinner
android:id="#+id/registration_stage_4_country_languages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clickable="false" />
NoDefaultSpinner.java can be found here: https://github.com/geftimov/android-components/blob/master/components/src/main/java/com/eftimoff/components/views/spinners/nodefault/NoDefaultSpinner.java
I have modified it to have a custom getView() method in the SpinnerProxy like this:
if (position < 0) {
if (layoutResource == -1) {
layoutResource = R.layout.no_default_spinner_item;
}
final TextView v =
(TextView) ((LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE)).inflate(
layoutResource, parent, false);
v.setText(getPrompt());
v.setPadding(0, 5, 0, 5);
return v;
}
return obj.getView(position, convertView, parent);
}
I edited your source code:
adapter = new ArrayAdapter<>(EditProfileNationalityActivity.this, R.layout.no_default_spinner_item, new String[] {""});
adapter.setDropDownViewResource(R.layout.no_default_spinner_item);
languagesSpinner.setAdapter(adapter);
I have a dialog that shows an error message,
i know i can take that error message and just make it invisible, and visible in the code,
but then the Dialog would still save room in it and it will just show as a white space.
I want the error message to be added dynamical so if no error message will be shown the dialog will be sized accordingly.
how do i do that ?
here is my Dialog >
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/textContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="14">
<EditText
android:id="#+id/barcode_activity_input_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:ems="10"
android:hint="Enter Serial Number"
android:inputType="number"
android:maxLength="14" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/barcode_activity_button_cancel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/barcode_activity_manual_input_check_box"
android:text="Cancel" />
<Button
android:id="#+id/barcode_activity_button_ok"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="#+id/barcode_activity_manual_input_check_box"
android:layout_toEndOf="#+id/barcode_activity_button_cancel"
android:text="Ok" />
<TextView
android:id="#+id/barcode_activity_text_view_warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textContainer"
android:layout_toRightOf="#+id/barcode_activity_image_view_warning"
android:paddingTop="5dp"
android:text="Serial doesn't match Workorder"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#f00000"
android:textSize="13dp" />
<ImageView
android:id="#+id/barcode_activity_image_view_warning"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#+id/textContainer"
android:background="#drawable/warning" />
<CheckBox
android:id="#+id/barcode_activity_manual_input_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/barcode_activity_image_view_warning"
android:text="Allow Serial In Workorder"
android:textSize="13dp" />
</RelativeLayout>
and here is my main file >
inputFieldDialog = new Dialog(this); // CASTING
//inputFieldDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
inputFieldDialog.setContentView(R.layout.aligment_manager_manual_input_layout); // INFLATING VIEW
Button cancelInputButton, confirmInputButton; //declaring BOXES
final EditText inputField;
TextView warningTextView;
ImageView warningImageView;
CheckBox warningCheckBox;
cancelInputButton = (Button) inputFieldDialog.findViewById(R.id.barcode_activity_button_cancel); //casting
confirmInputButton = (Button) inputFieldDialog.findViewById(R.id.barcode_activity_button_ok); //casting
inputField = (EditText) inputFieldDialog.findViewById(R.id.barcode_activity_input_editText); //casting
warningTextView = (TextView) inputFieldDialog.findViewById(R.id.barcode_activity_text_view_warning); //casting
warningImageView = (ImageView) inputFieldDialog.findViewById(R.id.barcode_activity_image_view_warning); //casting
warningCheckBox = (CheckBox) inputFieldDialog.findViewById(R.id.barcode_activity_manual_input_check_box); //casting
warningTextView.setVisibility(TextView.INVISIBLE); //sets warnings invisible
warningImageView.setVisibility(ImageView.INVISIBLE); //sets warnings invisible
warningCheckBox.setVisibility(CheckBox.INVISIBLE); //sets warnings invisible
cancelInputButton.setOnClickListener(new View.OnClickListener() { //listeners for the buttons
#Override
public void onClick(View v) {
inputFieldDialog.hide();
}
});
confirmInputButton.setOnClickListener(new View.OnClickListener() { //listeners for the buttons
#Override
public void onClick(View v) {
scanResults = String.valueOf(inputField.getText());
scanBarcodeText.setText(inputField.getText());
editor.putString("boxID", String.valueOf(inputField.getText())); //saves the data as antenaNamein shared prefrences
editor.commit();
if (checkIfIdMatched(String.valueOf(inputField.getText())) == true) { //checkks if id is maching the one in the workorder
aligmentManagerClass.scanFromBarcodeApproved(); //ID MACHED
if (mainDialog != null) {
mainDialog.show();
}
loaderScreenMainText.setText("initlizing WiFi");//shows the user on screen message
wifiWrapper myWifiWrapper = new wifiWrapper(); //- INIZILIZING WIFI
myWifiWrapper.checkWifiState(getApplication(), callbackFunctionForisWifiOn);
} else {
loaderScreenMainText.setText("Scan Doesn't Match Data In Workoder"); // notify onScreen User
if (mainDialog != null) { // hides the loading dialog
mainDialog.hide();
}
AlertDialog wrongNumberDialog = getAlertDialogForWrongId(); //shows to user alert dialog for Wrong Number
wrongNumberDialog.show(); // show it
}
}
For remove white space...
Use "View.GONE" property of setVisibility() method rather than "TextView.INVISIBLE".
Set below code for hide views
warningTextView.setVisibility(View.GONE);
warningImageView.setVisibility(View.GONE);
warningCheckBox.setVisibility(View.GONE);
And for visible view just user
warningTextView.setVisibility(View.VISIBLE);
warningImageView.setVisibility(View.VISIBLE);
warningCheckBox.setVisibility(View.VISIBLE);
You can add buttons dynamically by creating buttons in Java file
Add this XML to dialog like dialog.addView(...)
Then Create Dynamically Buttons by according to values like
for(){
Create Buttons and add to above layout
layout.addView(button);
}
Hope it will help.
So in my code I have 6 arrays (the 5 last could be empty) of objects. Each objects has a name and the array could have many of each object (every array are sorted so every item are grouped).
First, I have this 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="#drawable/fond4"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#color/white"
android:gravity="center"
android:text="#string/commentOpti"
android:textSize="20sp" />
<Button
android:id="#+id/choisirTroupe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:onClick="soumission"
android:text="#string/lancer" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#color/white"
android:gravity="center"
android:text="#string/casernes"
android:textSize="20sp" />
<!-- Caserne 1 -->
<LinearLayout
android:id="#+id/caserne1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#color/white"
android:orientation="horizontal" >
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:background="#drawable/caserne" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/deuxPoints"
android:textSize="25sp" />
</LinearLayout>
//Then 5 other like this 1st linearLayou
//The ids are incremented each time like caserne2 for the 2nd etc...
</ScrollView>
It look like this: https://gyazo.com/17a1276dfff5521d540fb6dc953df424
What I want to do is, for each object in each array (one array: one linear layout), to add a textView with the number of Item and an imageView which represent the object.
Next, you will find how I sort everything, that's not really important I think, but if you want to understand everything you'll have to give a look :p
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_optimisation);
LinearLayout caserne1 = (LinearLayout) findViewById(R.id.caserne1);
//...Doing this for the 5 others...
Intent intent = getIntent();
//Instanciation of my object
OptiClashOfClans o = new OptiClashOfClans();
//In fact, the number of linearLayout i'll have to work with
o.setNbCasernes(this.nbCaserne);
if (this.nbBarbares > 0)
o.ajouterFormation(1, this.nbBarbares);
//...Adding each object in on array...
o.setAFormer(o.triTroupe());
//And finally here i'll put each object in the good array
o.orgaCaserne(o);
Now we go for my problem, this portion of code is just next to the one I put previously, here is how I pick up the number of the same object in each array
for (int cptCaserne = 0; cptCaserne < this.nbCaserne; cptCaserne++) {
// Here I pick up the array of object I'll work with
Caserne casTmp = o.getCaserneNum(cptCaserne);
// Here I pick every object which are in the previous array
ArrayList<Troupe> enFormTmp = new ArrayList<Troupe>();
enFormTmp = casTmp.getEnFormation();
// To count where I am in the array of object
int cptAFormer = 0;
//To know if the next object is different from the one I'm working with
Troupe troupTmp = enFormTmp.get(cptAFormer);
int cptTroupTmp = 0;
//For the object t in the array of object
for (Troupe t : enFormTmp) {
cptTroupTmp = 0;
//While the object is the same from the one we're working with
while (!troupTmp.equals(t)) {
//Incrementing the previous counter
cptTroupTmp++;
cptAFormer++;
}
And finally here is how I don't really know how to do:
ImageView iView = new ImageView(Optimisation.this);
//To know which background i'll add to the image view
//I'll do this for each different object
if (t.getNom().equals("Barbare"))
iView.setImageResource(R.drawable.barbare);
//...
//The text view with the number of object I found
TextView tView = new TextView(Optimisation.this);
tView.setText("" + cptTroupTmp);
//And now it's here where I want to add the different views
switch (cptCaserne) {
case 0:
caserne1.addView(tView);
caserne1.addView(iView);
case 1:
caserne2.addView(tView);
caserne1.addView(iView);
case 2:
caserne3.addView(tView);
caserne1.addView(iView);
case 3:
caserne4.addView(tView);
caserne1.addView(iView);
}
troupTmp = enFormTmp.get(cptAFormer);
}
}
With this code I have an insane black screen when I'm going on this activity.
Here is what I want to do with in red the textView with the number of objet and in green the imageView of the object...
https://gyazo.com/31b16982ce30b66391bafdd2cd4d86fc
I've found some stuff to do with LayoutInflater but I haven't been successfull with these... Thanks a lot if you could help me.
PS: sorry for the mistakes, I think there are a lot, but in long post like this one, my school english isn't very effective ^^
Thanks again :)
Correct me if I'm wrong. But from what I understood you just need to accomplish what is being shown here https://gyazo.com/31b16982ce30b66391bafdd2cd4d86fc?
Base on your code you just have to add an additional LinearLayout having an horizontal orientation on each LinearLayout before adding the TextView and Image View.
Here's an example using your code:
LinearLayout innerLayout = new LinearLayout(Optimisation.this)
innerLayout.setOrientation(LinearLayout.HORIZONTAL);
ImageView iView = new ImageView(Optimisation.this);
//To know which background i'll add to the image view
//I'll do this for each different object
if (t.getNom().equals("Barbare"))
iView.setImageResource(R.drawable.barbare);
//...
//The text view with the number of object I found
TextView tView = new TextView(Optimisation.this);
tView.setText("" + cptTroupTmp);
innerLayout.addView(tView);
innerLayout.addView(iView);
//And now it's here where I want to add the different views
switch (cptCaserne) {
case 0:
caserne1.addView(innerLayout);
case 1:
caserne2.addView(innerLayout);
case 2:
caserne3.addView(innerLayout);
case 3:
caserne4.addView(innerLayout);
}
Feel free to adjust it if the Layout that I'm adding the innerLayout in is wrong. But basically, that's the idea.
How can I add a Total TextView inside ListView, as well as a Save Button under the ListView, dynamically?
Total is to be displayed similar to the following image. (note: not my data representation)
Activity A (Code Snippet)
long as=0; // for total
long bs=0;
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
// receive from B
switch (requestCode)
{
case 0:
result = data.getStringExtra("text"); // holds value (34,24)
name = data.getStringExtra("a"); // Project
as = as+Long.parseLong(result); // For total amount
Text = " " + name + " " + "RM" + result + ""; // display in listView
if (mClickedPosition == -1) {
//add new list
m_listItems.add(Text);
m_listBitmapItems.add(Global.img);
} else {
// edit listView value and image
m_listItems.set(mClickedPosition, Text);
m_listBitmapItems.set(mClickedPosition, Global.img);
}
adapter.notifyDataSetChanged();
listV.setAdapter(adapter);
break;
case 1: // Another name
result = data.getStringExtra("text");
name = data.getStringExtra("a");
description = data.getStringExtra("c");
bs = bs + Long.parseLong(result);
Log.d("FIRST", "result:" + result);
Text = " " + name + " " + "RM" + result + "";
if (mClickedPosition == -1)
{
m_listItems.add(Text);
} else {
m_listItems.set(mClickedPosition, Text);
}
adapter.notifyDataSetChanged();
listV.setAdapter(adapter);
break;
}
}
long samount = as + bs;
Toast.makeText(getActivity(), samount + "", Toast.LENGTH_LONG).show();
}
Activity A (Rendered Output)
Here I would like to add a Total TextView with value 58 (output as RM58), as well as a Save Button.
I am using the following xml files.
a.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/text"
android:textSize="20sp" />
<ListView android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
claims.xml (inside the listView)
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView android:id="#+id/imageView4"
android:layout_width="101dp"
android:layout_height="50dp" />
</AbsoluteLayout>
Thanks.
Add the following footer.xml file to res/layout http://developer.android.com/reference/android/widget/ListView.html
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent
android:orientation="vertical" >
// Format as you please
<TextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Total" />
</LinearLayout>
In your activity create and initialise the following variables.
LayoutInflater inflater = getLayoutInflater();
ViewGroup footer = (ViewGroup) inflater.inflate(R.layout.footer, listView,
false);
// You can add this when an item is added and remove it if the list is empty.
listView.addFooterView(footer, null, false);
tv = (TextView)footer.findViewById(R.id.tv);
// Update the text.
tv.append("t/"+ results.toString());
As mentioned in the comments, you can either use long total as a static class member and update it with the results value total+=results; taking care to reset the value to zero or decrement it if an item is removed from the list.
The other way is to loop through the items in your list, parsing the items to the object and getting the particular value of type long from each object and summing them as you go.
As you are now able to dynamically add your button, I'll add briefly for other users browsing, set the buttons visibility to GONE, so that the element does not displace the layout when it is not visible, HIDDEN makes the element not visible, but the space taken by the element affects the layout (and sometimes this is useful). Then the button visibility is dynamically changed to VISIBLE when an item is added to the list, and back to GONE when the list is cleared.
<Button
android:id="#+id/btn"
android:text="button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
http://developer.android.com/reference/android/transition/Visibility.html
wise people!
This is my first question here. I'm stuck with a problem that seemed pretty simple to solve to me. I am not able to show a custom Toast message in my Android app.
There are two custom layouts I've created
my_toast.xml - layout file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toast_layout_root"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="wrap_content">
<TextView
android:id = "#+id/text"
android:background="#color/yumist_red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textColor="#fff"
android:text = "ToastText"
android:gravity = "center"
/>
</LinearLayout>
my_toast_up.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toast_layout_root"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="wrap_content">
<ImageView
android:layout_width="30dp"
android:layout_height="10dp"
android:src="#drawable/chat_arrow"
android:rotation="180"
/>
<TextView
android:id = "#+id/text"
android:background="#color/yumist_red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textColor="#fff"
android:text = "ToastText"
android:gravity = "center"
/>
</LinearLayout>
The only difference in the two is an imageview containing an arrow image. I'm trying to create text-bubble-style Toast.
I am well able to show and use the first one in my app. But, when I use the second layout with the image, all I see is the Image and an empty TextView of the ImageView's width and standard height. I've tried a lot of posts and existing questions online, but I cannot find a solution to this.
Any help?
[java code for showing Toasts]
public static void showToast(String message, int type)
{ //'message' is the text to display, 'type' determines which of the three toasts is shown
/*
* There are three fixed toasts:
* 1. One pointing upwards (with an angle) and placed near the top. (upperNotification)
* 2. Placed in the default position, to show general messages. (no issues with this | mToast)
* 3. Placed to point at bar at the bottom. (lowerNotification)
*/
TextView textView = null ; //this will refer to the message TextView
//corresponding to the toast selected
Toast toast = null; //to refer to the toast to display
switch(type)
{
case MyToast.ARROW_DOWN:textView = lowerToastText; toast = lowerNotification; break;
case MyToast.ARROW_UP:textView = upperToastText; toast= upperNotification; break;
case MyToast.ARROW_NONE:textView = toastText; toast = mToast; break;
}
if(textView != null && toast != null)
{
System.out.println(message);
textView.setText(message);
toast.show();
}
else
{
System.out.println("NULL!");
}
}
//Below is the code I used to init these.
public static void setUpToast(Activity activity, LayoutInflater inflater)
{
mToast = new Toast(activity);
upperNotification = new Toast(activity);
lowerNotification = new Toast(activity);
View layout = inflater.inflate(R.layout.my_toast, null);
toastText = (TextView) layout.findViewById(R.id.text);
mToast.setView(layout);
mToast.setDuration(Toast.LENGTH_LONG);
layout = inflater.inflate(R.layout.my_toast_up, null);
upperToastText = (TextView) layout.findViewById(R.id.text);
upperNotification.setView(layout);
upperNotification.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, Dish.dpToPx(96, activity));
upperNotification.setDuration(Toast.LENGTH_LONG);
layout = inflater.inflate(R.layout.my_toast_down, null);
lowerToastText = (TextView) layout.findViewById(R.id.text);
lowerNotification.setView(layout);
lowerNotification.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, Dish.dpToPx(48, activity));
lowerNotification.setDuration(Toast.LENGTH_LONG);
}
I figured out a fix by trial-and-error myself.
In my layout, I had kept my TextViews' width to match its parent. That was causing it to shrink down the ImageView's width for some reason.
I changed it to WRAP_CONTENT and of the parent view to MATCH_PARENT and it fixed my problem.
I am, however, still curious if there's a way to show the text with the parent's width.