嗨我正在尝试使用一个广播组来浏览我的xml文件,该广播组在同一个活动中,但它只是为了第一次点击而在这里是我的xml文件
package com.example.carteacache;
import java.util.ArrayList;
import java.util.List;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
public Button bouton1;
public Button bouton2;
private Spinner spinner;
private RadioGroup radiobutO;
private RadioButton chRadio;
private String [] paysListe = {"Sénégal","Gambie","Sierra Leone","Burkina","Mali"};
@SuppressLint("CutPasteId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bouton1 = (Button)findViewById(R.id.button1);
bouton2 = (Button)findViewById(R.id.button2);
spinner = (Spinner)findViewById(R.id.spinner);
radiobutO =(RadioGroup) findViewById(R.id.radioGroup);
final RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup);
populateSpinner();
这是我导航的地方,认为可以让用户从一个到另一个xml文件的选项
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId)
{
chRadio =(RadioButton)rg.findViewById(radiobutO.getCheckedRadioButtonId());
checkedId = group.getCheckedRadioButtonId();
setContentView(R.layout.activity_main);
switch(checkedId)
{
case R.id.radio1:
Toast.makeText(MainActivity.this, chRadio.getText(), Toast.LENGTH_LONG).show();
setContentView(R.layout.activity_main);
break;
case R.id.radio2:
Toast.makeText(MainActivity.this, chRadio.getText(), Toast.LENGTH_LONG).show();
setContentView(R.layout.activity_main2);
// TODO Something
break;
case R.id.radio3:
Toast.makeText(MainActivity.this, chRadio.getText(), Toast.LENGTH_LONG).show();
setContentView(R.layout.activity_main3);
// TODO Something
break;
}
}
});
bouton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
@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;
}
@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.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void populateSpinner() {
//txtCategory.setText("");
List<String> pays = new ArrayList<String>();
for (int i = 0; i < paysListe.length; i++) {
pays.add(paysListe[i]);
}
// Creating adapter for spinner
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, pays);
// Drop down layout style - list view with radio button
spinnerAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(spinnerAdapter);
}
}
使用radioButton转到下一个xlm文件。 任何帮助将不胜感激