how to retrieve values from popup to main? - android

I have a main Activity that calls a popup window:
AddProduct.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent popup = new Intent(SingleVoucher.this, PopUp.class);
if (additionalProduct!=null) {
popup.putExtra("additionalamount", additionalQuantity);
popup.putExtra("additionalprice", additionalPrice);
popup.putExtra("additionalproduct", additionalProduct);
}
startActivity(popup);
}
});
the popup:
public class PopUp extends Activity {
private OnSubmitListener mListener;
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.popup_window);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
WindowManager.LayoutParams windowManager = getWindow().getAttributes();
windowManager.dimAmount = 0.75f;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
TextView SubmitAdditional = (TextView) findViewById(R.id.SubmitAdditional);
final EditText product = (EditText) findViewById(R.id.adittionalTextEdit);
final EditText qty = (EditText) findViewById(R.id.additionalQuantityTE);
final EditText price = (EditText) findViewById(R.id.adittionalPriceTE);
final Intent intent = getIntent();
final Context context = this;
SubmitAdditional.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String additionalProduct = product.getText().toString();
String additionalQuantity = qty.getText().toString();
String additionalPrice = price.getText().toString();
if (additionalProduct!=null && additionalPrice.isEmpty()==false && additionalQuantity.isEmpty()==false) {
intent.putExtra("additionalamount", additionalQuantity);
intent.putExtra("additionalprice", additionalPrice);
intent.putExtra("additionalproduct", additionalProduct);
}
else{
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Missing Details");
alert.setMessage("Some of the required fields are missing. please try again");
alert.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
}
}
});
getWindow().setLayout((int) (width * .8), (int) (height * .3));
}
}
and the XML of the poup window is:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/BlueGray">
<TextView
android:id="#+id/AdditionalTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="5dp"
android:layout_alignParentTop="true"
android:paddingTop="2dp"
android:text="Product Name"
android:textSize="18dp"
android:textColor="#color/White">
</TextView>
<EditText
android:id="#+id/adittionalTextEdit"
android:layout_width="260dp"
android:layout_height="50dp"
android:layout_below="#+id/AdditionalTitle"
android:background="#color/White"
android:textSize="12dp"
android:textColor="#color/Black"
android:layout_centerHorizontal="true"
android:gravity="top">
</EditText>
<TextView
android:id="#+id/additionalQuantityTV"
android:layout_marginLeft="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adittionalTextEdit"
android:text="Quantity"
android:textColor="#color/White"
android:textSize="15dp"
android:layout_marginTop="5dp">
</TextView>
<EditText
android:id="#+id/additionalQuantityTE"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/additionalQuantityTV"
android:layout_below="#+id/adittionalTextEdit"
android:background="#color/White"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="14dp"
android:layout_marginLeft="38dp"
android:numeric="integer"
android:textSize="14dp">
</EditText>
<TextView
android:id="#+id/adittionalPriceTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_below="#+id/additionalQuantityTV"
android:text="Overall price"
android:textColor="#color/White"
android:textSize="15dp"
android:layout_marginTop="5dp">
</TextView>
<EditText
android:id="#+id/adittionalPriceTE"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/adittionalPriceTV"
android:layout_below="#+id/additionalQuantityTE"
android:background="#color/White"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="14dp"
android:layout_marginLeft="10dp"
android:numeric="decimal"
android:textSize="14dp">
</EditText>
<TextView
android:id="#+id/popupClose"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_below="#+id/adittionalPriceTE"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="14dp"
android:textColor="#color/White">
</TextView>
<TextView
android:id="#+id/SubmitAdditional"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_below="#+id/adittionalPriceTE"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="14dp"
android:textColor="#color/White">
</TextView>
</RelativeLayout>
I want to get the values from the EditText and send them back to the parent.
How can I send the data back to the view who called the popup?

You can use startActivityForResult and setResult methods to achieve this.
In MainActivity start the popup activity like this
startActivityForResult(popup,1);
In popup activity use the setResult method to pass the value back to main activity.
Intent intent = new Intent();
intent.putExtra("data",data); // data is the value you need in parent
setResult(100,data);
In MainActivity use the onActivityResult method to get the data
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { value = data.getBundleExtra("data");

You will have to startActivityForResult()
then return result from PopUp Activity using setResult()
see this good link for statActivityForResult

Try to use startActivityForResult in order to show the popup.
Here is an example: http://developer.android.com/training/basics/intents/result.html
Then in the main activity you should override onActivityResult in order to have access to the info you sent from popup.

Related

Android AutoCompleteTextView return wrong string

I have a little problem in my android app. I want to put a word in an AutoCompleteTextView and then jump to a specific Activity(depend on the word that the user gave).
The problem is that, when i give a specific word, the program does not correspond with the correct answer as expected but returns a wrong toast message. However with the log that i put i see the correct answer. I think that the solution is silly but i stuck and need to solve this.
the code:
Activity.java
public class paralActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paral);
final String [] temp = {"one","two","three"};
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
actv.clearListSelection();
final RelativeLayout myRelative = (RelativeLayout) findViewById(R.id.find);
myRelative.setVisibility(View.INVISIBLE);
ImageView myImage = (ImageView) findViewById(R.id.aktoploika);
myImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(paralActivity.this, topParalActivity.class);
startActivity(intent);
}
});
ImageView myOtherImage = (ImageView) findViewById(R.id.aeroporika);
myOtherImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
myRelative.setVisibility(View.VISIBLE);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(paralActivity.this, android.R.layout.select_dialog_item, temp);
//Getting the instance of AutoCompleteTextView
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
actv.setThreshold(1);//will start working from first character
actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
actv.setTextColor(Color.RED);
ImageView findBeach = (ImageView) findViewById(R.id.find_beach);
findBeach.setOnClickListener(new View.OnClickListener() {
#Override
** public void onClick(View view) {
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
String choice = actv.getText().toString();
Log.i("Answer",choice);
if (choice == "one"){
Intent firstIntent = new Intent(paralActivity.this, nauagioActivity.class);
startActivity(firstIntent);
}else if (choice == temp[1]){
Intent secondIntent = new Intent(paralActivity.this, gerakasActivity.class);
startActivity(secondIntent);
}else if (choice == temp[2]){
Intent thirdIntent = new Intent(paralActivity.this, limnionasActivity.class);
startActivity(thirdIntent);
}else{
Toast.makeText(paralActivity.this,"wrong",Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}
To help u understand, in this activity a have 2 imageViews. When the user presses the second, a relativeLayout appears (with an AutoCompleteTextView and a button inside). After the user writes the word when presses the button it must go to the specific activity. I declared a String Array (temp[3]) with three words inside and 3 activities for each of the words.
The problem starts in the last onclick method that i put ** . Every time i put a correct word from the Array i take the Toast message but in the log i see the correct.
here is Activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_paral"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main"
android:scaleX="2"
tools:context="com.example.billy.zakynthosapp.paralActivity">
<TextView
android:id="#+id/categories"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome"
android:text="#string/categories"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textSize="11sp"
android:textStyle="bold"
android:textColor="#color/welcome"
android:textAllCaps="true"/>
<ImageView
android:id="#+id/aktoploika"
android:layout_centerHorizontal="true"
android:layout_width="130dp"
android:layout_height="50dp"
android:layout_below="#id/categories"
android:layout_marginTop="35dp"
android:scaleType="centerCrop"
android:src="#drawable/par1" />
<TextView
android:id="#+id/aktoploika_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/aktoploika"
android:layout_alignTop="#+id/aktoploika"
android:layout_alignRight="#+id/aktoploika"
android:layout_alignBottom="#+id/aktoploika"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/paralies"
android:textSize="22sp"
android:textColor="#color/categories"
android:textStyle="bold"/>
<ImageView
android:id="#+id/aeroporika"
android:layout_centerHorizontal="true"
android:layout_width="130dp"
android:layout_height="50dp"
android:layout_below="#id/aktoploika"
android:layout_marginTop="35dp"
android:scaleType="centerCrop"
android:src="#drawable/par2" />
<TextView
android:id="#+id/aeroporika_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/aeroporika"
android:layout_alignTop="#+id/aeroporika"
android:layout_alignRight="#+id/aeroporika"
android:layout_alignBottom="#+id/aeroporika"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/search"
android:textSize="22sp"
android:textColor="#color/categories"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/aeroporika"
android:layout_marginTop="50dp"
android:layout_centerInParent="true"
android:background="#color/categories"
android:scaleX="0.5">
<TextView
android:id="#+id/textView_1"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:textSize="20sp"
android:layout_centerHorizontal="true"
android:text="#string/find_paral"
android:textColor="#android:color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/find_beach"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="200dp"
android:src="#drawable/find"
android:onClick="find"/>
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView_1"
android:layout_marginTop="10dp"
android:ems="10"
android:text="">
<requestFocus />
</AutoCompleteTextView>
</RelativeLayout>
Can anyone help me with this?
Thanks a lot!
Try choice.equals("one") instead of choice == "one"

Cannot access resources in a layout in a PopupWindow, Objects are null referenced

I have an android application when clicked on an option from a side bar it goes to a fragment, and then into another fragment which has clickable radio buttons. When clicked on these it will create a popup window with some text fields in it.
Basically this is how the flow goes,
Activity --> Fragment 1 --> Fragment 2 --> PopupWindow
When i try to access the resources inside this popupWindow, in example:
damageComponenetAutoCompleteTextview = (AutoCompleteTextView) findViewById(R.id.popup_damage_component_item);
damageComponenetAutoCompleteTextview.requestFocus();
in the line damageComponenetAutoCompleteTextview.requestFocus(); it gives me an error,
Attempt to invoke virtual method on a null object reference
I believe it's due to a wrong view i'm referring when calling on the Resources. Hope someone could point me to what i'm doing wrong. Thanks in Advance.
This is the method i'm using to create the popupWindow.
public void showDamagedItemEntryPopup(RadioButton radioButton, View view){
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup viewG = ((ViewGroup)view.findViewById(R.id.damaged_comp_popup));
//I tried passing the root view to inflate() method instead of passing it null. Didn't work.
//View popupView = layoutInflater.inflate(R.layout.component_selection_popup, null);
View popupView = layoutInflater.inflate(R.layout.component_selection_popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setAnimationStyle(R.style.popupAnimation);
//I tried setting the content view manually but didnt work
//popupWindow.setContentView(view.findViewById(R.id.damaged_comp_popup));
Button buttonClose = (Button)popupView.findViewById(R.id.close_add_component_btn);
// Close button damaged item popop window
buttonClose.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
originalAmount = (EditText)this.findViewById(R.id.popup_add_component_original_amount);
customerContribution = (EditText)this.findViewById(R.id.popup_percentage);
quantity = (EditText)this.findViewById(R.id.popup_quantity);
finalAmount = (EditText)this.findViewById(R.id.popup_add_component_final_amount);
remarks = (EditText)this.findViewById(R.id.popup_add_component_remarks);
// Item Spinner
itemSpinnerArray = new ArrayList<String>();
itemSpinnerArray.add("Select Item");
// Status Spinner
ArrayList<String> statusSpinnerArray = new ArrayList<String>();
statusSpinnerArray.add("MR");
statusSpinnerArray.add("DR");
statusSpinnerArray.add("SP");
// Error comes at this point initially. When these Resource access line codes are commented, the popup works fine.
damageComponenetAutoCompleteTextview = (AutoCompleteTextView) findViewById(R.id.popup_damage_component_item);
damageComponenetAutoCompleteTextview.requestFocus();
ArrayAdapter<String> itemSpinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, itemSpinnerArray);
damageComponenetAutoCompleteTextview.setThreshold(1);
damageComponenetAutoCompleteTextview.setAdapter(itemSpinnerArrayAdapter);
damageComponenetAutoCompleteTextview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//int index = cityNames.indexOf(actvCity.getText().toString());
itemSpinnerValue = (String) parent.getItemAtPosition(position);
Log.d("SK-->", "----------------------------------------------------------");
Log.d("SK-->","itemSpinnerValue: " + itemSpinnerValue);
}
});
statusSpinner = (Spinner)this.findViewById(R.id.popup_status_spinner);
ArrayAdapter<String> statusSpinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, statusSpinnerArray);
statusSpinner.setAdapter(statusSpinnerArrayAdapter);
//Creating a text Watcher
TextWatcher textWatcher = new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
//here, after we introduced something in the EditText we get the string from it
//String answerString = originalAmount.getText().toString();
if (originalAmount.getText().toString().trim().equals("") || customerContribution.getText().toString().trim().equals("")
|| quantity.getText().toString().trim().equals("")) {
// Error , one or more editText are empty
}
else
{
calculateFinalAmount();
}
//and now we make a Toast
//modify "yourActivity.this" with your activity name .this
//Toast.makeText(yourActivity.this,"The string from EditText is: "+answerString,0).show();
}
};
// Adding Text Watcher to our text boxes
originalAmount.addTextChangedListener(textWatcher);
customerContribution.addTextChangedListener(textWatcher);
quantity.addTextChangedListener(textWatcher);
// Show the popup
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
}
This is the XML i'm using for the popup.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/damaged_comp_popup"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/popup_wire">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="2dp"
android:background="#color/popup_background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<AutoCompleteTextView
android:id="#+id/popup_damage_component_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:hint="#string/damaged_componenet_item_string"/>
<Spinner
android:id="#+id/popup_status_spinner"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/popup_damage_component_item"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp" />
<EditText
android:id="#+id/popup_add_component_original_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/popup_damage_component_item"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="22dp"
android:layout_toRightOf="#+id/popup_status_spinner"
android:ems="10"
android:hint="#string/original_amount_string"
android:inputType="number" />
<EditText
android:id="#+id/popup_percentage"
android:layout_width="52dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/popup_status_spinner"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="2dp"
android:layout_marginTop="22dp"
android:ems="10"
android:hint="#string/percentage_string"
android:inputType="number" />
<TextView
android:id="#+id/popup_percentageMark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/popup_percentage"
android:layout_toRightOf="#+id/popup_percentage"
android:text="#string/percentage_string"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="1dp"
android:layout_marginRight="0dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<EditText
android:id="#+id/popup_quantity"
android:layout_width="46dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/popup_percentage"
android:layout_alignBottom="#+id/popup_percentage"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="6dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/popup_percentageMark"
android:ems="10"
android:hint="#string/quantity_string"
android:inputType="number" />
<EditText
android:id="#+id/popup_add_component_final_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/popup_quantity"
android:layout_alignBottom="#+id/popup_quantity"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/popup_quantity"
android:ems="10"
android:hint="#string/final_amount_string"
android:inputType="number" />
<EditText
android:id="#+id/popup_add_component_remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/popup_percentage"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="22dp"
android:ems="10"
android:hint="#string/remarks_string"
android:inputType="text|textMultiLine" />
<Button
android:id="#+id/add_component_btn"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_below="#+id/popup_add_component_remarks"
android:background="#drawable/correct"
android:layout_marginBottom="15dp"
android:onClick="onSaveItem"/>
<Button
android:id="#+id/close_add_component_btn"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_below="#+id/popup_add_component_remarks"
android:layout_toRightOf="#+id/add_component_btn"
android:layout_marginLeft="10dp"
android:background="#drawable/cancel"/>
</RelativeLayout>
</LinearLayout>
It seems your damageComponenetAutoCompleteTextview belongs to the popupWindow which you inflated at top.
So try changing
damageComponenetAutoCompleteTextview = (AutoCompleteTextView) findViewById(R.id.popup_damage_component_item);
To
damageComponenetAutoCompleteTextview = (AutoCompleteTextView) popupView.findViewById(R.id.popup_damage_component_item);
And other relevant elements as well.

Android there is some way for don't waste layout when orientation change?

I have an application that have a TableLayout with 60 texviews.
The user can touch them and a DialogActivity start for take the text and background color of the clicked TextView.
But the app have a bug that some times all TextView take the color of the first inputed color and inside of the code i haven't a loop that assign the color.
I think that, the problem come from to the orientation of the screen (possible?).
Because the Activity that contain TableLayout is landscape and the Dialog is portrait.
Infact when the Dialog start behind it there is the Activity that change his orientation with the Dialog and all textviews change their color.
How can i avoid this bug?
Why this happend?
Acitivity landscape:
public class ActivitySetOrario extends ActionBarActivity {
//Static perch� cosi non perdo i dati inseriti in precedenza!
static int clickedTextViewId; // Declare TextView as class level member field
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_orario);
MySQLiteHelper db = new MySQLiteHelper(this);
//Get all materie inside database
List<Materia> materia = db.getAllMaterie();
//change all TextView inputed from user
if(materia.isEmpty()){
//do nothing
}else {
for (Materia mat : materia) {
//Change all the TextView with values stored inside the database
TextView changedtextview = (TextView) findViewById(mat.getID());
changedtextview.setText(mat.getMateria());
changedtextview.setBackgroundColor(mat.getColor());
}
}
}//Fine oncreate
//Prende indietro la materia aggiunta dall'ActivityAddMateria
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 1) {
if (resultCode == RESULT_OK) {
MySQLiteHelper db = new MySQLiteHelper(this);
String result = data.getStringExtra("result"); //Take the materia from Dialog
int color = data.getIntExtra("color", 1); //Take the color from Dialog
//Here i need to recognize row and column
db.addMateria(new Materia(clickedTextViewId, result, color));
TextView clickedtextView = (TextView) findViewById(clickedTextViewId); //(TextView) view;
clickedtextView.setText(result);
clickedtextView.setBackgroundColor(color);
}
if (resultCode == RESULT_CANCELED) {
//Nessuna materia inserita
}
}
}//onActivityResult
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_set_orario, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case R.id.draw_orario:
//addMateria();
MySQLiteHelper db = new MySQLiteHelper(this);
db.deleteMateria();
onStart();
return true;
case R.id.save_data_orario:
//SERIALIZZO I DATI CHE DOVRA PRENDERE ActivityOrario
backToOrario();
finish();
return true;
case R.id.exit_orario:
//Torno alla schermata orario annullo ogni modifica NON SERIALIZZO
backToOrario();
finish();
return true;
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//Torna alla ActivityOrario
public void backToOrario(){
Intent myIntent = new Intent(ActivitySetOrario.this, ActivityOrario.class);
startActivity(myIntent);
}
public void addMateria(View v){
//To get ID of your TextView do this
clickedTextViewId = v.getId();
//StartActivityForResult perche mi aspetto la materia inserita dall'altra activity
Intent myIntent = new Intent(ActivitySetOrario.this, ActivityAddMateria.class);
ActivitySetOrario.this.startActivityForResult(myIntent, 1);
}
}
The Dialog portrait Activity:
public class ActivityAddMateria extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_materia);
final Button exit_button = (Button) findViewById(R.id.exit_dialog_materia);
exit_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//No input
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
//Exit from Dialog
finish();
}
});
final Button accept_button = (Button) findViewById(R.id.add_materia);
accept_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Find EditText for take data
EditText nome_materia = (EditText)findViewById(R.id.nome_materia);
//Put result into variable result that is send back
String result = nome_materia.getText().toString();
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.group1);
int radioButtonID = radioGroup.getCheckedRadioButtonId();
View radioButton = radioGroup.findViewById(radioButtonID);
Drawable background = radioButton.getBackground();
if (background instanceof ColorDrawable) {
int color = ((ColorDrawable) background).getColor();
Intent returnIntent = new Intent();
returnIntent.putExtra("result",result).putExtra("color",color);
setResult(RESULT_OK,returnIntent);
}
// Exit to Dialog
finish();
}
});
}
}
The xml of the first activity:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_orario"
android:id="#+id/table">
<TableRow
android:id="#+id/dayrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="35dp" >
<TextView
android:id="#+id/d1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Lun."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Mar."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Mer."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Gio."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ven."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sab."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<ScrollView
android:id="#+id/scrollorario"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="#+id/prima_riga"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/h1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mat11"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text=""/>
<TextView
android:id="#+id/mat12"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat13"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat14"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat15"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat16"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
</TableRow>
<!--TOO LONG THE XML I CUT IT THE OTHER ROW ARE THE SAME-->
</LinearLayout>
</ScrollView>
</TableLayout>
Some screenshoot:
You shouldn't be using the ids of the textviews in your database: they can change between different compilations of your app. Which could be the culprit. However, the only way they're all being set is in the for loop: you should verify your database is correct and verify that loop is not running every time.

Parse information into listView

i am asking you for help. As you see from the picture it is a result that i should have, but, at the moment i have information orinted on my left corner. what i am doing wrog?
MainActivity.java
public class MainActivity extends ListActivity {
/** Items entered by the user is stored in this ArrayList variable */
ArrayList<String> list = new ArrayList<String>();
/** Declaring an ArrayAdapter to set items to ListView */
ArrayAdapter<String> adapter;
TextView mTvSDate;
TextView mTvSName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickListener listener = new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.SecondElementActivity");
startActivityForResult(intent, 1);
}
};
ImageButton addBtn = (ImageButton) findViewById(R.id.addBtn);
addBtn.setOnClickListener(listener);
Log.d("Suceess1","Sucess1");
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Defining the ArrayAdapter to set items to ListView
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
// Getting reference to TextView tv_sage of the layout file activity_student
// mTvSDate = (TextView) findViewById(R.id.editDate);
// Getting reference to TextView tv_sname of the layout file activity_student
mTvSName = (TextView)findViewById(R.id.editName);
Log.d("Suceess5","Sucess5");
// Fetching data from a parcelable object passed from MainActivity
NoteElement drug = getIntent().getParcelableExtra("drug");
// MyAdapter adapter = new MyAdapter(this, generateData());
Log.d("Suceess6","Sucess6");
list.add(mTvSName.getText().toString());
mTvSName.setText(drug.mSName);
adapter.notifyDataSetChanged();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
SecondElementActivity.java
public class SecondElementActivity extends Activity{
EditText mEtSDate;
EditText mEtSName;
Button btnSave;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_element);
// Getting a reference to EditText et_sname of the layout activity_main
mEtSName = (EditText)findViewById(R.id.editName);
// Getting a reference to EditText et_sage of the layout activity_main
mEtSDate = (EditText)findViewById(R.id.editDate);
// Getting a reference to Button btn_ok of the layout activity_main
btnSave = (Button)findViewById(R.id.btnSave);
// Setting onClick event listener for the "OK" button
btnSave.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Creating an instance of NoteElement class with user input data
NoteElement drug = new NoteElement(
mEtSDate.getText().toString(),
mEtSName.getText().toString());
// Creating an intent to open the activity MainActivity
Intent intent = new Intent(getBaseContext(), MainActivity.class);
// Passing data as a parecelable object to MainActivity
intent.putExtra("drug",drug);
// Opening the activity
startActivity(intent);
}
});
}
}
Parcelable class NoteElement.java
public class NoteElement implements Parcelable{
String mSDate;
String mSName;
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
/**
* Storing the NoteElement data to Parcel object
**/
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mSDate);
dest.writeString(mSName);
}
/**
* A constructor that initializes the NoteElement object
**/
public NoteElement(String sDate, String sName){
this.mSDate = sDate;
this.mSName = sName;
}
/**
* Retrieving NoteElement data from Parcel object
* This constructor is invoked by the method createFromParcel(Parcel source) of
* the object CREATOR
**/
private NoteElement(Parcel in){
this.mSDate = in.readString();
this.mSName = in.readString();
}
public static final Parcelable.Creator<NoteElement> CREATOR = new Parcelable.Creator<NoteElement>() {
#Override
public NoteElement createFromParcel(Parcel source) {
return new NoteElement(source);
}
#Override
public NoteElement[] newArray(int size) {
return new NoteElement[size];
}
};
}
And my activity_main have such a .xml 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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageButton
android:id="#+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_action_new"
android:contentDescription="#string/desc"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/addBtn"
android:layout_alignParentLeft="true"
android:layout_marginLeft="53dp"
android:text="#string/mainTxt"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="32sp" />
<!-- Student version -->
<TextView
android:id="#+id/tv_sname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true" />
<TextView
android:id="#+id/tv_sdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true" />
<!-- List -->
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:layout_toLeftOf="#+id/addBtn" />
</RelativeLayout>
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="#+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_action_new"
android:contentDescription="#string/desc"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/addBtn"
android:layout_alignParentLeft="true"
android:layout_marginLeft="53dp"
android:text="#string/mainTxt"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="32sp" />
<!-- Date -->
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/textView1"
android:layout_marginRight="36dp"
android:layout_marginTop="14dp"
android:layout_toLeftOf="#+id/editDate"
android:text="#string/date" />
<EditText
android:id="#+id/editDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/editName"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="date"
android:hint="#string/str_hnt_date" />
<!-- Name -->
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignBottom="#+id/editName"
android:layout_alignLeft="#+id/date"
android:text="#string/name" />
<EditText
android:id="#+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/date"
android:ems="10"
android:hint="#string/str_hnt_name" />
<!-- Dosage -->
<TextView
android:id="#+id/dosage"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/editText3"
android:layout_alignBottom="#+id/editText3"
android:layout_alignLeft="#+id/notes"
android:text="#string/dosage" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editName"
android:layout_below="#+id/editName"
android:ems="10"
android:hint="#string/str_hnt_dosage" />
<!-- Notes -->
<TextView
android:id="#+id/notes"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/editText4"
android:layout_alignBottom="#+id/editText4"
android:layout_alignRight="#+id/name"
android:text="#string/notes" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText3"
android:layout_below="#+id/editText3"
android:ems="10"
android:hint="#string/str_hnt_notes"/>
<!-- buttons: Save and Selete-->
<Button
android:id="#+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText4"
android:layout_below="#+id/notes"
android:layout_marginTop="20dp"
android:text="#string/btnSave" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnSave"
android:layout_marginLeft="20dp"
android:layout_toLeftOf="#+id/addBtn"
android:layout_toRightOf="#+id/btnSave"
android:text="#string/btnDelete" />
</RelativeLayout>
Okay so you have two activities total right?
Here's the deal: Look at your image. Activity 1 starts activity 2 right? And you're expecting to get information from your activity 2 back to activity 1, correct? Alright.
First thing to learn:
startActivity(intent);
This method states that you will just initiate an activity but expect nothing back from it. So even if you want to send information back to activity 1 THROUGH activitiy 2 it will not work. Instead you must do this:
startActivityForResult(intent, 1);
The second parameter is an integer that can help you differentiate between different activity calls, it is not important for you right now.
Now, because you say "ForResult" in your method above, in your MainActivity now you must implement this:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// here you will work with the code.
// data is your intent data sent from activity 2
// where you say this in your own code:
// Passing data as a parecelable object to MainActivity
// intent.putExtra("drug",drug);
}
Now the last thing to note:
In SecondElementActivity.java where you have this:
// Opening the activity
startActivity(intent);
It is wrong. You know why? because you're saying that you want to start a new activity. But in Android you already have a parent for this activity, which is activity 1. So your activity 1 called 2, when you end activity 2 it will go back to 1. So, replace that line for this:
setResult(RESULT_OK, intent);
finish();
EDIT:
Also I don't know if this is correct, I don't do it this way, so here is my fix:
OnClickListener listener = new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.SecondElementActivity");
startActivity(intent);
}
};
When you say you want to make a new intent you should pass two parameters:
Intent intent = new Intent(this, SecondElementActivity.class);
The second parameter is the name of the class you want to call.
You can try like this :
activity_main.xml
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageButton
android:id="#+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher"
android:contentDescription="#string/hello_world"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/addBtn"
android:layout_centerHorizontal="true"
android:text="mainTxt"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="32sp" />
<!-- List -->
<ListView
android:id="#+id/myListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp" />
</RelativeLayout>
Follow This tutorial for populating ListView just change adapter and row.xml from that tutorial
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv_sdate "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="5dp"
android:textSize="12sp" >
</TextView>
<TextView
android:id="#+id/tv_sname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tv_sdate "
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="12sp" >
</TextView>
</RelativeLayout>
http://hmkcode.com/android-custom-listview-items-row/

Android Activity as dialog black border

I have activity as a dialogue, all the shows I like. But I have a problem with a frame around them. Just like here.
My Activity:
public class AlarmAlert extends Activity implements Alarms.AlarmSettings {
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
AlarmAlertWakeLock.acquire(this);
/*
* FIXME Intentionally verbose: always log this until we've fully
* debugged the app failing to start up
*/
Log.v("AlarmAlert.onCreate()");
DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
Intent i = getIntent();
mAlarmId = i.getIntExtra(Alarms.ID, -1);
Alarms.getAlarm(getContentResolver(), this, mAlarmId);
mKlaxon = new AlarmKlaxon();
mKlaxon.postPlay(this, mAlarmId);
/* Set the title from the passed in label */
setTitleFromIntent(i);
/*
* allow next alarm to trigger while this activity is active
*/
Alarms.disableSnoozeAlert(AlarmAlert.this);
Alarms.disableAlert(AlarmAlert.this, mAlarmId);
Alarms.setNextAlert(this);
mKlaxon.setKillerCallback(new AlarmKlaxon.KillerCallback() {
public void onKilled() {
if (Log.LOGV)
Log.v("onKilled()");
updateSilencedText();
/* don't allow snooze */
mSnoozeButton.setEnabled(false);
dismiss();
mState = KILLED;
}
});
updateLayout();
SharedPreferences settings = getSharedPreferences(
AlarmClock.PREFERENCES, 0);
if (settings.getBoolean(AlarmClock.PREF_SHAKE_SNOOZE, true)) {
mShakeListener = new ShakeListener(this);
mShakeListener
.setOnShakeListener(new ShakeListener.OnShakeListener() {
public void onShake() {
snooze();
if (mCaptchaSnooze == 0)
finish();
}
});
}
}
private void setTitleFromIntent(Intent i) {
mLabel = i.getStringExtra(Alarms.LABEL);
if (mLabel == null || mLabel.length() == 0) {
mLabel = getString(R.string.default_label);
}
setTitle(mLabel);
}
private void updateSilencedText() {
TextView silenced = (TextView) findViewById(R.id.silencedText);
silenced.setText(getString(R.string.alarm_alert_alert_silenced,
mDuration / 1000 * 60));
silenced.setVisibility(View.VISIBLE);
}
private void updateLayout() {
setContentView(R.layout.alarm_alert);
My alert_alarm.xml (Dialog).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="327dp"
android:layout_height="295dp"
android:background="#drawable/alertbg"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/silencedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/ltgrey"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="230dp"
android:gravity="center_horizontal" >
<Button
android:id="#+id/snooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/snooze_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
<Button
android:id="#+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/dismiss_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:id="#+id/tvDD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tvDate"
android:layout_alignLeft="#+id/tvDate"
android:text="Medium Text"
android:textSize="20dp"
android:textColor="#a6a6a6" />
<TextView
android:id="#+id/tvDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/relativeLayout1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="55dp"
android:layout_marginLeft="30dp"
android:text="Medium Text"
android:textSize="25dp"
android:textColor="#a6a6a6" />
<com.boxclocks.android.alarmclock.dc
android:id="#+id/digitalClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="58dp"
android:text="DigitalClock"
android:textColor="#a6a6a6"
android:textSize="70dp" />
</RelativeLayout>
How do I remove the border.
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Dialog
You have two options. You can set the theme of your Activity to
Theme_Translucent_NoTitleBar
Or you have to create a new theme and load it with a custom nine patch as specified here
How to remove border from Dialog?

Categories

Resources