2016-09-17 8 views
-4

ので、私は2つの活動 1とAndroidアプリがある - メイン 2 - 第二条件が満たされていればチェックボックス?

主な活動は、私がどこかのチェックボックスの状態を作るために、チェックボックスを使用する方法を知りたいRelativeLayoutに1つのチェックボックスを持っていますImageView = VISIBLE、TextView = GONEを第2のアクティビティにしたい、その逆の場合はその逆をチェックします。

私は共有された環境設定を使用しようとしましたが、意図は残っていますが、チェックボックスが重要でないか画面が空白になってしまうところがあります。もう1つのことは、メインアクティビティでは、onClickを持っていて、すでにインテントがあるボタンがあることです。私は、2番目のアクティビティのチェックボックスを使ってif条件を作成する方法を知りたいだけです。悲しいことに、私はコード全体を投稿するだろうが、私はそれをあまりにも悪くして、これを全面的に把握しようとしており、もう意味をなさない。

ok私はいくつか試してみましたが、投稿された答えを試しましたが、少なくとも今すぐ共有できるほどのコードをクリーンアップすることができましたが、本当にひどく間違ってしまい、アプリを閉じます。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:layout_margin="0dp" 
    android:singleLine="false" 
    android:id="@+id/activity_display_message" 
    tools:context=".MainActivity" 
    android:focusableInTouchMode="false" 
    android:focusable="true" 
    android:nestedScrollingEnabled="false" 
    android:orientation="vertical" 
    android:weightSum="1"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:scaleType="fitXY" 
     android:src="@drawable/logo" 
     android:visibility="gone" 
     android:id="@+id/iV2" /> 

    <me.grantland.widget.AutofitLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:maxLines="1" 
      android:textStyle="bold" 
      android:textSize="275sp" 
      android:layout_weight=".5" 
      android:textAlignment="center" 
      android:text="LOGO" 
      android:visibility="invisible" 
      android:id="@+id/restxttop" 
      android:elegantTextHeight="false" /> 
    </me.grantland.widget.AutofitLayout> 

    <me.grantland.widget.AutofitLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight=".5" 
     android:textAlignment="center" 
     android:maxLines="1" 
     android:textSize="275sp" 
     android:text="SIGNAGE" 
     android:id="@+id/restxtbot" 
     /> 
    </me.grantland.widget.AutofitLayout> 
</LinearLayout> 

activity_display_message.xml

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:id="@+id/rlay" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    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="sam.plsnyc.com.plsign.MainActivity"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Company" 
     android:id="@+id/textView" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignBottom="@+id/editText" 
     android:textAlignment="center" 
     android:textIsSelectable="false" /> 
    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/textView" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Signage" 
     android:id="@+id/textView2" 
     android:layout_below="@+id/textView" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignBottom="@+id/editText2" 
     android:textAlignment="center" 
     android:textIsSelectable="false" /> 
    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText2" 
     android:layout_below="@+id/editText" 
     android:layout_alignLeft="@+id/editText" 
     android:layout_alignStart="@+id/editText" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Make Sign" 
     android:id="@+id/button" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@+id/editText2" /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imgView" 
     android:focusable="true" 
     android:src="@drawable/logo" 
     android:scaleType="fitXY" 
     android:visibility="visible" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 
    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Use Logo" 
     android:id="@+id/logobox" 
     android:layout_below="@+id/textView2" 
     android:layout_alignParentStart="true" /> 
</RelativeLayout> 

MainActivity.java

public class MainActivity extends Activity { 
    public final static String KEY_CHECKED = "chkd"; 
    CheckBox lbox; 
    Button button; 
    EditText etxt; 
    EditText etxt2; 
    String toptxt; 
    String bottxt; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main);{ 

      button = (Button) findViewById(R.id.button); 
      button.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 
        etxt = (EditText) findViewById(R.id.editText); 
        toptxt = etxt.getText().toString(); 
        etxt2 = (EditText) findViewById(R.id.editText2); 
        bottxt = etxt2.getText().toString(); 

        Intent i = new Intent(v.getContext(), DisplayMessageActivity.class); 
        i.putExtra("text1", toptxt); 
        i.putExtra("text2", bottxt); 
        startActivity(i); 

        lbox = (CheckBox) findViewById(R.id.logobox); 
        Intent i2 = new Intent (MainActivity.this, DisplayMessageActivity.class); 
        i2.putExtra(KEY_CHECKED, lbox.isChecked()); 
        startActivity(i2); 
       } 
      }); 
     } 
    } 
} 

DisplayMessageActivity.java

public class DisplayMessageActivity extends Activity { 
    TextView ttxt; 
    TextView btxt; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     this.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_display_message); 

     btxt = (TextView) findViewById(R.id.restxtbot); 
     btxt.setText(getIntent().getStringExtra("text2")); 
     AutofitHelper.create(btxt); 

     ImageView image = (ImageView) findViewById(R.id.iV2); 

     Boolean chk = getIntent().getBooleanExtra(MainActivity.KEY_CHECKED, false); 
     if (chk) 
     { 
      ttxt.setVisibility(View.GONE); 
      image.setVisibility(View.VISIBLE); 
     }else{ 
      ttxt.setVisibility(View.VISIBLE); 
      ttxt = (TextView)findViewById(R.id.restxttop); 
      ttxt.setText(getIntent().getStringExtra("text1")); 
      AutofitHelper.create(ttxt); 
      ttxt.setPaintFlags(ttxt.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG); 
     } 
    } 
} 
+0

がために、あなたのXMLを提供します両方の活動 –

+0

あなたが既に試したことを投稿しない限り、私たちはあなたを助けることはできません..それはちょうどstackoverflowが動作する方法です –

答えて

0

あなたがメインから2番目の活動を開く場合は、この単純な場合には他の目的ににisChecked値を置くことができる値の静的

関連する問題