当前位置: 代码迷 >> Android >> Android 资源数组引述
  详细解决方案

Android 资源数组引述

热度:69   发布时间:2016-05-01 20:56:26.0
Android 资源数组引用

package Zhiyeceshi.co.cc;

import net.miidi.credit.MiidiCredit;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class StartActivity extends Activity {
 RadioGroup mRadioGroup;
 TextView mTextView1;
 RadioButton rb1, rb2;
 Button button1;

 int mclick = 0;
 int mclick1 = 0;
 int mclick2 = 0;

 int[] test = { R.string.test_title2, R.string.test_title3,
   R.string.test_title4, R.string.test_title5, R.string.test_title6,
   R.string.test_title7, R.string.test_title8, R.string.test_title9,
   R.string.test_title10, R.string.test_title11,
   R.string.test_title12, R.string.test_title13,
   R.string.test_title14, R.string.test_title15,
   R.string.test_title16, R.string.test_title17,
   R.string.test_title18, R.string.test_title19,
   R.string.test_title20, R.string.test_title21,
   R.string.test_title22, R.string.test_title23,
   R.string.test_title24, R.string.test_title25,
   R.string.test_title26, R.string.test_title27,
   R.string.test_title28, R.string.test_title29,
   R.string.test_title30,R.string.test_title31,
   R.string.test_title32,
   R.string.test_title33,
   R.string.test_title34,
   R.string.test_title35,

 };

 int[] choiceA = { R.string.title2_answer_a, R.string.title3_answer_a,
   R.string.title4_answer_a, R.string.title5_answer_a,
   R.string.title6_answer_a, R.string.title7_answer_a,
   R.string.title8_answer_a, R.string.title9_answer_a,
   R.string.title10_answer_a, R.string.title11_answer_a,
   R.string.title12_answer_a, R.string.title13_answer_a,
   R.string.title14_answer_a, R.string.title15_answer_a,
   R.string.title16_answer_a, R.string.title17_answer_a,
   R.string.title18_answer_a, R.string.title19_answer_a,
   R.string.title20_answer_a, R.string.title21_answer_a,
   R.string.title22_answer_a, R.string.title23_answer_a,
   R.string.title24_answer_a, R.string.title25_answer_a,
   R.string.title26_answer_a, R.string.title27_answer_a,
   R.string.title28_answer_a, R.string.title29_answer_a,
   R.string.title30_answer_a,
   R.string.title31_answer_a,
   R.string.title32_answer_a,
   R.string.title33_answer_a,
   R.string.title34_answer_a,
   R.string.title35_answer_a,

 };
 int[] choiceB = { R.string.title2_answer_b, R.string.title3_answer_b,
   R.string.title4_answer_b, R.string.title5_answer_b,
   R.string.title6_answer_b, R.string.title7_answer_b,
   R.string.title8_answer_b, R.string.title9_answer_b,
   R.string.title10_answer_b, R.string.title11_answer_b,
   R.string.title12_answer_b, R.string.title13_answer_b,
   R.string.title14_answer_b, R.string.title15_answer_b,
   R.string.title16_answer_b, R.string.title17_answer_b,
   R.string.title18_answer_b, R.string.title19_answer_b,
   R.string.title20_answer_b, R.string.title21_answer_b,
   R.string.title22_answer_b, R.string.title23_answer_b,
   R.string.title24_answer_b, R.string.title25_answer_b,
   R.string.title26_answer_b, R.string.title27_answer_b,
   R.string.title28_answer_b, R.string.title29_answer_b,
   R.string.title30_answer_b,
   R.string.title31_answer_b,
   R.string.title32_answer_b,
   R.string.title33_answer_b,
   R.string.title34_answer_b,
   R.string.title35_answer_b,

 };

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

  MiidiCredit.init(StartActivity.this, "5262", "0n6ocmvhdu9em7fv", false);
  setContentView(R.layout.main);

  button1 = (Button) findViewById(R.id.button1);
  Button helpback = (Button) findViewById(R.id.helpback);
  mTextView1 = (TextView) findViewById(R.id.tv);
  mRadioGroup = (RadioGroup) findViewById(R.id.RG);
  rb1 = (RadioButton) findViewById(R.id.rb1);
  rb2 = (RadioButton) findViewById(R.id.rb2);
  mTextView1.setText(R.string.test_title1);
  rb1.setText(R.string.title1_answer_a);
  rb2.setText(R.string.title1_answer_b);

  // mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
  // {
  //
  // @Override
  // public void onCheckedChanged(RadioGroup group, int checkedId) {
  // // TODO Auto-generated method stub
  // if (rb1.isChecked() || rb2.isChecked()) {
  // if (mclick < 4) {
  // mTextView1.setText(test[mclick]);
  // rb1.setText(choiceA[mclick1]);
  // rb2.setText(choiceB[mclick2]);
  // mclick++;
  // mclick1++;
  // mclick2++;
  //
  // }
  //
  // }
  //
  // }
  // });

  button1.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    if (rb1.isChecked() || rb2.isChecked()) {
     if (mclick < 34) {
      mTextView1.setText(test[mclick]);
      rb1.setText(choiceA[mclick1]);
      rb2.setText(choiceB[mclick2]);
      mclick++;
      mclick1++;
      mclick2++;

      if (mclick >= 34) {
       Intent intent5 = new Intent(StartActivity.this,
         Result.class);
       startActivity(intent5);
       finish();
      }

     }

    } else {
     Toast.makeText(StartActivity.this, "请进行选择", 1000).show();
    }

    // rb1.setText(choiceA[0]++);
    // rb2.setText(choiceB[0]++);

   }
  });

  // mRadioGroup.setOnClickListener(new OnClickListener() {
  //
  // @Override
  // public void onClick(View v) {
  // // TODO Auto-generated method stub
  // // if (rb1.isPressed() || rb2.isPressed()) {
  // // mTextView1.setText(R.string.test_title2);
  // // rb1.setText(R.string.title2_answer_a);
  // //
  // // rb2.setText(R.string.title2_answer_b);
  // // }
  // Toast.makeText(StartActivity.this, "loveyou", 1000).show();
  //
  // }
  // });

  // mTextView1.setText(R.string.test_title1);
  // rb1.setText(R.string.title1_answer_a);
  // rb2.setText(R.string.title1_answer_b);
  // mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
  // {
  //
  // @Override
  // public void onCheckedChanged(RadioGroup group, int checkedId) {
  // // TODO Auto-generated method stub
  // switch (checkedId) {
  // case checkedId == rb1.getId():
  //
  // break;
  //
  // default:
  // break;
  // }

  // if (rb1.isChecked() || rb2.isChecked()) {
  // mTextView1.setText(R.string.test_title2);
  // rb1.setText(R.string.title2_answer_a);
  // rb2.setText(R.string.title2_answer_b);
  // }
  //
  // if (rb1.isChecked() || rb2.isChecked()) {
  // mTextView1.setText(R.string.test_title3);
  // rb1.setText(R.string.title3_answer_a);
  // rb2.setText(R.string.title3_answer_b);
  // }
  // if (group.getCheckedRadioButtonId() == rb1.getId()
  // || group.getCheckedRadioButtonId() == rb2.getId()) {
  // mTextView1.setText(R.string.test_title2);
  // rb1.setText(R.string.title2_answer_a);
  // rb2.setText(R.string.title2_answer_b);
  // if (group.getCheckedRadioButtonId() == rb1.getId()
  // || group.getCheckedRadioButtonId() == rb2.getId()) {
  //
  // mTextView1.setText(R.string.test_title3);
  // rb1.setText(R.string.title3_answer_a);
  // rb2.setText(R.string.title3_answer_b);
  //
  // }
  // }

  // }
  //
  // });

  // if (checkedId == rb1.getId() || checkedId == rb2.getId()) {
  // mTextView1.setText(R.string.test_title2);
  // rb1.setText(R.string.title2_answer_a);
  // rb2.setText(R.string.title2_answer_b);
  //
  // }

  // if (checkedId == rb1.getId() || checkedId == rb2.getId()) {
  // mTextView1.setText(R.string.test_title2);
  // rb1.setText(R.string.title2_answer_a);
  // rb1.setText(R.string.title2_answer_b);
  //
  // } else if (checkedId == rb1.getId() || checkedId ==
  // rb2.getId()) {
  // mTextView1.setText(R.string.test_title3);
  // rb1.setText(R.string.title3_answer_a);
  // rb1.setText(R.string.title3_answer_b);
  //
  // }

  helpback.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent intent4 = new Intent(StartActivity.this,
      ZhiyeceshiActivity.class);
    startActivity(intent4);
    finish();

   }
  });

 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // TODO Auto-generated method stub
  SubMenu subMenu = menu.addSubMenu(0, 1, 0, "关于");

  return super.onCreateOptionsMenu(menu);
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  if (item.getItemId() == 1) {
   AlertDialog.Builder builder = new Builder(StartActivity.this);
   builder.setTitle("软件信息");
   builder.setMessage(R.string.about_cont);
   builder.create().show();

  }
  return super.onOptionsItemSelected(item);
 }

 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
   setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }

 }
}

  相关解决方案