Tecnologia do Blogger.
RSS

[androidbrasil-dev] if com 2 EditText

ae.. 

criei meu primeiro app para calcular tamanho de tela de projecao. 

segue MainActivity.java: 

  1. package br.test;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.text.method.HideReturnsTransformationMethod;  
  6. import android.view.Menu;  
  7. import android.view.View;  
  8. import android.view.Window;  
  9. import android.widget.Button;  
  10. import android.widget.EditText;  
  11. import android.widget.RadioGroup;  
  12. import android.widget.TextView;  
  13.   
  14. public class MainActivity extends Activity {  
  15.       
  16.   
  17.     double altura, tamanho, largura;  
  18.       
  19.     @Override  
  20.     protected void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.         setContentView(R.layout.activity_main);  
  23.           
  24.         Button btncalcular = (Button) findViewById(R.id.btncalcular);  
  25.         btncalcular.setOnClickListener(new View.OnClickListener() {  
  26.               
  27.             @Override  
  28.             public void onClick(View v) {  
  29.                 // TODO Auto-generated method stub  
  30.                   
  31.                 EditText edttam = (EditText) findViewById(R.id.edttam);  
  32.                   
  33.                 tamanho = Double.parseDouble(edttam.getText().toString());  
  34.                   
  35.                 RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);  
  36.                   
  37.                 int op = rg.getCheckedRadioButtonId();  
  38.                   
  39.                 if (op==R.id.radio0) {altura = (tamanho * 2.54) * 0.49;  
  40.                                      largura = (tamanho * 2.54) * 0.87;}  
  41.                         else  
  42.                             if (op==R.id.radio1) {altura = (tamanho * 2.54) * 0.6;  
  43.                                                  largura = tamanho * 2.54 * 0.8;}  
  44.                               
  45.               
  46.                 TextView txtalt = (TextView) findViewById(R.id.txtalt);  
  47.                 txtalt.setText(String.valueOf(altura + " Cm"));  
  48.                   
  49.                 TextView txtlargura = (TextView) findViewById(R.id.txtlargura);  
  50.                 txtlargura.setText(String.valueOf(largura +" Cm"));  
  51.                   
  52.               
  53.           
  54.                   
  55.             }  
  56.               
  57.             });  
  58.     }  
  59.   
  60.   
  61.     @Override  
  62.     public boolean onCreateOptionsMenu(Menu menu) {  
  63.         // Inflate the menu; this adds items to the action bar if it is present.  
  64.         getMenuInflater().inflate(R.menu.main, menu);  
  65.         return true;  
  66.     }  
  67.       
  68. }  


segue meu activity_main.xml: 

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity" >  
  10.   
  11.     <TextView  
  12.         android:id="@+id/textView1"  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="@string/formato" />  
  16.   
  17.     <RadioGroup  
  18.         android:id="@+id/radioGroup1"  
  19.         android:layout_width="wrap_content"  
  20.         android:layout_height="wrap_content"  
  21.         android:layout_alignParentLeft="true"  
  22.         android:layout_below="@+id/textView1"  
  23.         android<img src="http://javafree.uol.com.br/forum/images/smiles/icon_surprised.gif">rientation="horizontal" >  
  24.   
  25.         <RadioButton  
  26.             android:id="@+id/radio0"  
  27.             android:layout_width="wrap_content"  
  28.             android:layout_height="wrap_content"  
  29.             android:checked="true"  
  30.             android:focusable="false"  
  31.             android:focusableInTouchMode="false"  
  32.             android:text="16x9" />  
  33.   
  34.         <RadioButton  
  35.             android:id="@+id/radio1"  
  36.             android:layout_width="wrap_content"  
  37.             android:layout_height="wrap_content"  
  38.             android:focusable="false"  
  39.             android:focusableInTouchMode="false"  
  40.             android:text="4x3" />  
  41.     </RadioGroup>  
  42.   
  43.     <TextView  
  44.         android:id="@+id/textView2"  
  45.         android:layout_width="wrap_content"  
  46.         android:layout_height="wrap_content"  
  47.         android:layout_alignLeft="@+id/radioGroup1"  
  48.         android:layout_below="@+id/radioGroup1"  
  49.         android:layout_marginTop="18dp"  
  50.         android:text="@string/tamanho" />  
  51.   
  52.     <requestFocus />  
  53.   
  54.     <EditText  
  55.         android:id="@+id/edttam"  
  56.         android:layout_width="match_parent"  
  57.         android:layout_height="wrap_content"  
  58.         android:layout_alignLeft="@+id/textView2"  
  59.         android:layout_below="@+id/textView2"  
  60.         android:layout_marginTop="14dp"  
  61.         android:ems="10"  
  62.         android:inputType="number" />  
  63.   
  64.     <Button  
  65.         android:id="@+id/btncalcular"  
  66.         android:layout_width="match_parent"  
  67.         android:layout_height="wrap_content"  
  68.         android:layout_alignLeft="@+id/edttam"  
  69.         android:layout_below="@+id/edttam"  
  70.         android:layout_marginTop="22dp"  
  71.         android:text="@string/btncalc" />  
  72.   
  73.     <TextView  
  74.         android:id="@+id/textView3"  
  75.         android:layout_width="wrap_content"  
  76.         android:layout_height="wrap_content"  
  77.         android:layout_alignLeft="@+id/btncalcular"  
  78.         android:layout_below="@+id/btncalcular"  
  79.         android:layout_marginTop="24dp"  
  80.         android:text="@string/altura" />  
  81.   
  82.     <TextView  
  83.         android:id="@+id/txtlargura"  
  84.         android:layout_width="match_parent"  
  85.         android:layout_height="wrap_content"  
  86.         android:layout_alignLeft="@+id/textView4"  
  87.         android:layout_below="@+id/textView4"  
  88.         android:clickable="false"  
  89.         android:focusable="false"  
  90.         android:focusableInTouchMode="false"  
  91.         android:longClickable="false"  
  92.         android:textAppearance="?android:attr/textAppearanceMedium"  
  93.         android:textColor="#FF0000" />  
  94.   
  95.     <TextView  
  96.         android:id="@+id/txtalt"  
  97.         android:layout_width="match_parent"  
  98.         android:layout_height="wrap_content"  
  99.         android:layout_alignLeft="@+id/textView3"  
  100.         android:layout_below="@+id/textView3"  
  101.         android:clickable="false"  
  102.         android:focusable="false"  
  103.         android:focusableInTouchMode="false"  
  104.         android:longClickable="false"  
  105.         android:textAppearance="?android:attr/textAppearanceMedium"  
  106.         android:textColor="#FF0000" />  
  107.   
  108.     <TextView  
  109.         android:id="@+id/textView4"  
  110.         android:layout_width="wrap_content"  
  111.         android:layout_height="wrap_content"  
  112.         android:layout_alignLeft="@+id/txtalt"  
  113.         android:layout_below="@+id/txtalt"  
  114.         android:layout_marginTop="23dp"  
  115.         android:text="@string/largura" />  
  116.   
  117. </RelativeLayout>  



preciso de ajuda para fazer o seguinte... 

atualmente se digita o tamanho da tela em polegadas e o app converte para cm retornando com a altura e a largura da tela... sendo que sempre antes deve se informar o formato da tela (4x3 ou 16x9) 

gostaria que o usuario ao inves de digitar o tamanho , digitasse ou a altura ou a largura direto e o app verificasse qual foi digitado e retornasse com o que nao foi digitado.. mantendo a opcao de escolha do formato.. 

nao consegui usar if para verificar o formato e tb se foi digitado ou altura ou largura.. 


alguem poderia me ajudar com isso? 

agradeco muito ajuda desde ja.. 

obrigado 

abs

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário